Demo07_FileCopyPlusPlus.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package J20250725;
  2. import java.io.*;
  3. /**
  4. * @author WanJl
  5. * @version 1.0
  6. * @title Demo07_FileCopyPlusPlus
  7. * @description
  8. * @create 2025/7/25
  9. */
  10. public class Demo07_FileCopyPlusPlus implements FileCopy{
  11. /**
  12. *
  13. * @param src
  14. * @param desc
  15. * @throws IOException
  16. */
  17. @Override
  18. public void copy(String src, String desc) throws IOException {
  19. //创建基础流--文件字节输入流
  20. FileInputStream fis=new FileInputStream(src);
  21. //创建基础流--文件字节输出流
  22. FileOutputStream fos=new FileOutputStream(desc);
  23. //创建处理流--字节缓冲输入流
  24. BufferedInputStream bis=new BufferedInputStream(fis);
  25. //创建处理流--字节缓冲输出流
  26. BufferedOutputStream bos=new BufferedOutputStream(fos);
  27. //创建一个byte类型数组
  28. byte[] bys=new byte[1024];
  29. int length; //每次读取的长度,每次读取多少字节
  30. while ((length=bis.read(bys))!=-1){
  31. bos.write(bys,0,length);
  32. }
  33. //先关处理流
  34. bos.close();
  35. bis.close();
  36. //后关基础流
  37. fos.close();
  38. fis.close();
  39. }
  40. public static void main(String[] args) {
  41. try {
  42. long start = System.currentTimeMillis();
  43. new Demo07_FileCopyPlusPlus().copy("D:/植物大战僵尸杂交版v2.0.88安装程序.zip","E:/植物大战僵尸杂交版v2.0.88安装程序.zip");
  44. long end = System.currentTimeMillis();
  45. System.out.println(end-start);
  46. } catch (IOException e) {
  47. e.printStackTrace();
  48. }
  49. }
  50. }