import java.io.*;
public class CopyTest
{
public static void main(String[] args) throws IOException
{
FileReader fr =null;
fr =new FileReader("CopyTest.java");
BufferedReader br =new BufferedReader(fr);
FileWriter fw =null;
fw =new FileWriter("CopyThis.txt");
BufferedWriter bw =new BufferedWriter(fw);
String hasRead =null;
while((hasRead=br.readLine())!=null)
{
bw.write(hasRead);
}
fr.close();
fw.close();
}
}
------解决方案--------------------------------------------------------
关闭流的时候注意清空BufferedWriter流,调用bw.flush(),就行了 ,这是BufferedWriter的特性!
------解决方案--------------------------------------------------------
用到流时(不管字符流或字节流),用完必须关闭,关闭有两层含义:对于普通流(非缓冲流)即释放系统或网络资源,对于缓冲流,即先刷新缓冲区,再释放占用的资源,close相当于flush+close,写一个close就行了,jdk源码里,缓冲流的close方法实现就包含了flush方法,亲,一定记得关哦