java字符缓冲流复制文件

2021/5/1 12:55:22

本文主要是介绍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();
    }
}




这篇关于java字符缓冲流复制文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程