Demo10_CopyText.java 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package J20250725;
  2. import java.io.FileReader;
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. /**
  6. * @author WanJl
  7. * @version 1.0
  8. * @title Demo10_CopyText
  9. * @description
  10. * @create 2025/7/25
  11. */
  12. public class Demo10_CopyText implements TextCopy{
  13. /**
  14. * 文本复制
  15. * @param src 开始位置
  16. * @param desc 目标位置
  17. */
  18. @Override
  19. public void copy(String src, String desc) throws IOException {
  20. FileReader fr=new FileReader(src);
  21. FileWriter fw=new FileWriter(desc);
  22. //创建一个字符数组
  23. char[] chars=new char[8192];
  24. int length;
  25. while ((length=fr.read(chars))!=-1){
  26. fw.write(chars,0,length);
  27. }
  28. fr.close();
  29. fw.close();
  30. }
  31. public static void main(String[] args) throws IOException {
  32. long start = System.currentTimeMillis();
  33. new Demo10_CopyText().copy("D:/我的文件.txt","E:/我的文件.txt");
  34. long end = System.currentTimeMillis();
  35. System.out.println(end-start);
  36. }
  37. }