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

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))