package com.copy_test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class copy01 {
public static void main(String[] args) {
//创建两个流
FileInputStream fis = null;
FileOutputStream fos = null;
try {
//将文件和目标位置赋值给两个流
fis = new FileInputStream("/Users/fuyifeng/Downloads/110432.1.mp4");
fos = new FileOutputStream("/Users/fuyifeng/Desktop/110432.1.mp4");
//核心:一边读一边写
byte[] bytes = new byte[1024 * 1024];//每次最多访存1MB
int readCount = 0;
while((readCount = fis.read(bytes)) != -1){
fos.write(bytes,0,readCount);
}
fos.flush();
//刷新
}catch(Exception e ){
//关闭流
e.printStackTrace();
}finally {
if(fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
08-22