PrintWriter:字符类型的打印输出流。用于向文本输出流打印对象的格式化形式。
package com.mzs.chat.base;
import java.io.*;
public class Test {
public static void main(String[] args) throws FileNotFoundException, IOException {
//File file = new File("C:\\test.txt");
FileOutputStream fos = new FileOutputStream("C:\\test.txt");
PrintWriter printWriter = new PrintWriter("C:\\test.txt");
printWriter.write("hello world");
printWriter.append('-');
printWriter.println("tom");
printWriter.printf("%s\n", "this is the test");
printWriter.flush();
printWriter.close();
}
}
本文介绍了如何使用Java中的PrintWriter类进行文件的字符类型打印输出。通过实例演示了write、append、println和printf等方法的用法,展示了如何向文本文件写入字符串并进行格式化输出。
432

被折叠的 条评论
为什么被折叠?



