| 1234567891011121314151617181920212223242526272829303132 |
- package course;
- import java.io.*;
- /**
- * @author WanJl
- * @version 1.0
- * @title BufferedCopy
- * @description
- * @create 2026/8/7
- */
- public class BufferedCopy implements CopyFile{
- @Override
- public String copy(String src, String desc) throws IOException {
- //1、创建文件字节输出流和缓冲流对象
- FileOutputStream fos=new FileOutputStream(desc);
- BufferedOutputStream bos=new BufferedOutputStream(fos);
- //2创建文件字节输入流和缓冲流对象
- FileInputStream fis=new FileInputStream(src);
- BufferedInputStream bis=new BufferedInputStream(fis);
- byte[] bytes=new byte[8192];
- int count;
- while ((count=bis.read(bytes))!=-1){
- bos.write(bytes,0,count);
- }
- bis.close();
- fis.close();
- bos.close();
- fos.close();
- return "复制成功";
- }
- }
|