import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/*
* 用打印流改进复制文本文件的操作
* */
public class PrintWriterDemo {
public static void main(String[] args) throws IOException{
//创建流
BufferedReader br = new BufferedReader(new FileReader("a.txt"));
PrintWriter pw = new PrintWriter(new FileWriter("b.txt"),true);
//读数据,并写到pw
String line = null;
while((line=br.readLine())!=null)
{
pw.println(line);
System.out.println("print OK");
}
//关闭流
pw.close();
br.close();
}
}
//怎么能关闭流后,通过程序打开b.txt,看其中的内容? |
|