java字符缓冲流复制文件


import java.io.*;

//复制文件
public class BufferStream1 {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader("E:\\Workpace\\ccc.txt"));
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("E:\\Workpace\\ddd.txt"));
//        char[] chars = new char[1024];
//        int len;
//        while ((len = bufferedReader.read(chars)) != -1){
//            bufferedWriter.write(new String(chars,0,len));
//        }
        String line;
        while((line = bufferedReader.readLine()) != null){
            bufferedWriter.write(line);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }
        bufferedReader.close();
        bufferedWriter.close();
    }
}


posted @ 2021-05-01 11:09  code-G  阅读(73)  评论(0编辑  收藏  举报