package cn.itcast.copy;
/*
* 字符流缓冲区对象复制文本文件
* 数据源: c:\\a.txt BufferedReader+FileReader 读取文本行
* 数据目的: d:\\a.txt BufferedWriter+FileWriter 写行
*/
import java.io.*;
public class CopyTextBuffered {
public static void main(String[] args)throws IOException {
//创建缓冲区对象,传递字符流匿名对象
BufferedReader bfr = new BufferedReader(new FileReader("c:\\a.txt"));
BufferedWriter bfw = new BufferedWriter(new FileWriter("d:\\a.txt"));
//读取一行,写一行,写换行,刷新
String line = null;
while((line = bfr.readLine())!=null){
bfw.write(line);
bfw.newLine();
bfw.flush();
}
bfw.close();
bfr.close();
}
}
|
|