package J20250725;

import java.io.*;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo12_BufferedWriter
 * @description
 * @create 2025/7/25
 */
public class Demo12_CopyTextPlus implements TextCopy{

    /**
     * 文本复制
     * @param src  开始位置
     * @param desc 目标位置
     */
    @Override
    public void copy(String src, String desc) throws IOException {
        //创建基础流-字符流
        FileReader fr=new FileReader(src);
        FileWriter fw=new FileWriter(desc);
        //创建处理流-缓冲流
        BufferedReader br=new BufferedReader(fr);
        BufferedWriter bw=new BufferedWriter(fw);

        //创建一个字符数组
        char[] chars=new char[8192];
        int length;
        while ((length=br.read(chars))!=-1){
            bw.write(chars,0,length);
        }
        br.close();
        bw.close();
        fr.close();
        fw.close();
    }

    public static void main(String[] args) throws IOException {

        long start = System.currentTimeMillis();
        new Demo10_CopyText().copy("D:/我的文件.txt","E:/我的文件.txt");

        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}