字节缓冲流一次读写一个字节数组(复制视频)---最快的
字节缓冲流一次读写一个字节数组-----(复制视频)
复制视频
- 根据数据源创建字节输入缓冲流对象
- 根据目的地创建字节输出缓冲流对象
- 读写数据,复制视频
- 释放资源
以图文和代码的形式讲解
数据源
目的地
- 代码
package Demo;import java.io.*;public class Demo { public static void main(String[] args) throws IOException { //创建数据源+字节输入缓冲流 BufferedInputStream inBfile = new BufferedInputStream(new FileInputStream("D:\\JPkanna\\kanna.mp4")); //创建目的地+字节输出缓冲流 BufferedOutputStream outBfile = new BufferedOutputStream(new FileOutputStream("D:\\item\\Hellow\\src\\kanna")); //利用byte数组来进行以此复制一个字节 byte[] bytes = new byte[1024]; int len; int i= (int) System.currentTimeMillis(); while((len=inBfile.read(bytes))!=-1){outBfile.write(bytes,0,len); } int j=(int)System.currentTimeMillis(); System.out.println("运行了"+(j-i)+"毫秒"); //释放资源 inBfile.close(); outBfile.close(); }}
输出的内容
字节缓冲流一次读写一个字节数组是最快的!!!!!
方法名 | 说明 |
---|---|
System.currentTimeMillis(); | 可以利用该方法测试系统运行时间 |