12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package J20250725;
- import java.io.*;
- /**
- * @author WanJl
- * @version 1.0
- * @title Demo07_FileCopyPlusPlus
- * @description
- * @create 2025/7/25
- */
- public class Demo07_FileCopyPlusPlus implements FileCopy{
- /**
- *
- * @param src
- * @param desc
- * @throws IOException
- */
- @Override
- public void copy(String src, String desc) throws IOException {
- //创建基础流--文件字节输入流
- FileInputStream fis=new FileInputStream(src);
- //创建基础流--文件字节输出流
- FileOutputStream fos=new FileOutputStream(desc);
- //创建处理流--字节缓冲输入流
- BufferedInputStream bis=new BufferedInputStream(fis);
- //创建处理流--字节缓冲输出流
- BufferedOutputStream bos=new BufferedOutputStream(fos);
- //创建一个byte类型数组
- byte[] bys=new byte[1024];
- int length; //每次读取的长度,每次读取多少字节
- while ((length=bis.read(bys))!=-1){
- bos.write(bys,0,length);
- }
- //先关处理流
- bos.close();
- bis.close();
- //后关基础流
- fos.close();
- fis.close();
- }
- public static void main(String[] args) {
- try {
- long start = System.currentTimeMillis();
- new Demo07_FileCopyPlusPlus().copy("D:/植物大战僵尸杂交版v2.0.88安装程序.zip","E:/植物大战僵尸杂交版v2.0.88安装程序.zip");
- long end = System.currentTimeMillis();
- System.out.println(end-start);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|