package J20250725;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author WanJl
 * @version 1.0
 * @title Demo10_CopyText
 * @description
 * @create 2025/7/25
 */
public class Demo10_CopyText 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);
        //创建一个字符数组
        char[] chars=new char[8192];
        int length;
        while ((length=fr.read(chars))!=-1){
            fw.write(chars,0,length);
        }
        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);
    }
}
