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();
}
}