牛客网Java刷题知识点之字节缓冲区练习之从A处复制文本文件到B处(BufferedReader、BufferedWriter)、复制文本文件的原理图解

时间:2022-04-01 21:00:43

 

 

  不多说,直接上干货!

 

 

 

CopyTextByBufTest.java

牛客网Java刷题知识点之字节缓冲区练习之从A处复制文本文件到B处(BufferedReader、BufferedWriter)、复制文本文件的原理图解

 

package zhouls.bigdata.DataFeatureSelection.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class CopyTextByBufTest {
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("a.txt");        
        BufferedReader bufr = new BufferedReader(fr);
        FileWriter fw = new FileWriter("b.txt");
        BufferedWriter bufw = new BufferedWriter(fw);
        
        String line = null;
        while((line=bufr.readLine())!=null){
            bufw.write(line);
            bufw.newLine();
            bufw.flush();
        }
        bufw.close();
        bufr.close();
    }
}