文件流close的小问题

import java.io.*;
public class TestFileReader{
    public static void main(String[] args){
        FileWriter fw1 = null;
        FileWriter fw2 = null;
        FileReader fr = null;
        try{
            fw1 = new FileWriter("/home/jimort/文档/test1.txt");
            fr = new FileReader("/home/jimort/文档/test1.txt");
            fw2 = new FileWriter("/home/jimort/文档/test2.txt");
            for(int i=0;i<1000;i++){
                fw1.write((char)i);
            }
            fw1.close();      
            int b;
            
            while((b = fr.read())!=-1){
                fw2.write((char) b);
            }
fw1.close();          //当把fw1放在这里关闭,内容就复制不了到fw2了

            fr.close();
            fw2.close();
            }catch(FileNotFoundException fe){
                fe.printStackTrace();
                System.exit(-1);
            }catch(IOException ie){
                ie.printStackTrace();
                System.exit(-1);
            }
        }
}
posted @ 2015-05-06 18:34  awenzero  阅读(139)  评论(0编辑  收藏  举报