【PrintWriter】字符输出流
练习一、用方法一在a.txt文件里写入“hello zhaiyujia”
package org.zhaiyujia.pkg1;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class TestPrintWriter {
public static void main(String[] args) {
try {
PrintWriter pw= new PrintWriter("f:/a.txt");
pw.println("hello zhaiyujia");//写到缓冲区里,没有到文件里
pw.flush();//用flush方法把缓冲区里的数据刷新到文件
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
练习二、用方法二在a.txt文件里写入“翟羽佳好漂亮”
练习三、FileOutputStream fos=new FileOutputStream(“f:/a.txt”);可以直接把fos转换成PrintWriter