import java.io.*;
/* 复制视频
通字节流一次一个字节 用时:227726毫秒
一次一个数组的字节 用时:334毫秒
缓冲字节流一次一个字节 用时:617毫秒
一次一个数组的字节 用时:77毫秒
*/
public class TestDemo {
public static void main(String[] args) throws IOException {
FileInputStream filein = new FileInputStream("C:\\Users\\Administrator\\Videos\\Captures\\test.mp4");
FileOutputStream fileout = new FileOutputStream("D:\\JavaProject\\text\\test.mp4");
BufferedInputStream bis = new BufferedInputStream(filein);
BufferedOutputStream bos = new BufferedOutputStream(fileout);
long startTime = System.currentTimeMillis();
//使用普通字节流,一次一个字节赋值视频
// int by ;
// while ((by = filein.read())!=-1){
// fileout.write(by);
// }//用时:227726毫秒
//使用普通字节流,一次一个数组的字节赋值视频
// int len;
// byte[] bys = new byte[1024];
// while ((len = filein.read(bys)) != -1){
// fileout.write(bys,0,len);
// }//用时:334毫秒
//使用缓冲字节流一次一个字节复制文件
// int by ;
// while ((by = bis.read()) != -1){
// bos.write(by);
// }//用时:617毫秒
//使用缓冲字节流一次一个数组的字节复制视频
int len;
byte[] bys = new byte[1024];
while ((len = bis.read(bys)) != -1){
bos.write(bys,0,len);
}//用时:77毫秒
long endTime = System.currentTimeMillis();
System.out.println("用时:"+(endTime-startTime)+"毫秒");
filein.close();
fileout.close();
}
}
字节流复制视频
最新推荐文章于 2024-09-10 10:21:38 发布