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

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

作者: Joy_yang17 | 来源:发表于2018-05-23 19:12 被阅读6次
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();
    }
    }

}

相关文章

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/zildjftx.html