PrintWriter:
1、PrintWriter是可以打印任意类型数据的,这里指的是它的print方法和println方法
2、使用PrintWriter(OutputStream out, boolean autoFlush)构造和PrintWriter(Writer out, boolean autoFlush)构造时可以实现自动刷新,不过有前提,只有在调用 println、printf 或 format方法时才会自动刷新
例: FileOutputStream fos = new FileOutputStream("print.txt");
PrintWriter pw1 = new PrintWriter(fos,true);
pw1.write("hello");
pw1.print("world");
pw1.println("haha"); //这个语句会把在缓冲中的内容写进文本,如果没有这个语句,则hello 和world不会写进文档,需要调用flush方法才可写进
|
|