//缓存数据流
@Test
public void testBufferReaderAndWriter() throws IOException{
//创建文件字符输入流
Reader in=new FileReader("abc.txt");
BufferedReader br=new BufferedReader(in);
Writer out=new FileWriter("abc4.txt");
BufferedWriter bw=new BufferedWriter(out);
//进行读写操作
String content=null;
int i=0;
while((content=br.readLine())!=null){
if(i!=0){
bw.write("\n");
}
bw.write(content);
i++;
}
/**
* 如果这里不调用BufferedWriter的close()或flush(),在文件中你看不到写入的数据
*
*/
br.close();
//bw.flush();
bw.close();
}
原文地址:http://www.cnblogs.com/liuquande/p/3790580.html