檔案的複製通過字元流和緩衝流(Buffered)

weixin_34402408發表於2018-05-23
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();
    }
    }

}

相關文章