文件的复制通过字符流和缓冲流(Buffered)

2018-05-23  本文已影响6人  Joy_yang17
public class FileReaderAndWriter {
    public static void main(String[] args) {
       try {
        FileReader fr = new FileReader("learn.txt");
        FileWriter fw = new FileWriter("learn3.txt");
        
         BufferedReader bf = new BufferedReader(fr);
         BufferedWriter bw = new BufferedWriter(fw);
         
         String text;
         while ((text = bf.readLine()) != null) {
            bw.write(text+"\n");
        }
         
         bw.flush();
         
         bw.close();
         bf.close();
         fw.close();
         fr.close();
         
         System.out.println("done");
        
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    }

}
上一篇下一篇

猜你喜欢

热点阅读