package com.yundait.Demo03;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
/**
* 使用文件字节流实现文件的复制
* @author zhang
*/
public class FileInputStreamDemo03 {
public static void main(String[] args) throws Exception {
//1创建文件输入流对象
FileInputStream fis = new FileInputStream("C:\\Users\\Administrator\\Pictures\\Saved Pictures\\001.png");
//2创建文件输出流对象
FileOutputStream fos = new FileOutputStream("C:\\Users\\Administrator\\Pictures\\Saved Pictures\\003.png");
//3一遍读取文件一遍写入文件
byte[] bytes = new byte[1024];
int count;
while ((count = fis.read(bytes))!=-1){
fos.write(bytes,0,count);
}
//4关闭流通道
fis.close();
fos.close();
System.out.println("复制完毕");
}
}
视频链接:16.08 字节流复制文件_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1Tz4y1X7H7?spm_id_from=333.788.videopod.episodes&vd_source=b5775c3a4ea16a5306db9c7c1c1486b5&p=8