字节流复制视频以及对比时长

package com.czie.iot1913.lps.IO.BufferStream;

import java.io.*;

/**
* FileName: CopyAviDemo01
* Author: lps
* Date: 2022/3/24 20:25
* Sign:刘品水 Q:1944900433
*/
public class CopyAviDemo01 {
public static void main(String[] args) throws Exception {
//开始时间
long startTime = System.currentTimeMillis();
//method01();//用时:7毫秒 一次读写一个字节数组
//method02();//用时:5184毫秒 一次读取一个字节
//method03();//用时:3毫秒 字节缓冲流一次读取一个字节数组
method04();//用时:3462毫秒 字节缓冲流一次读取一个字节
long endTime = System.currentTimeMillis();
System.out.println("用时:" + (endTime - startTime) + "毫秒");


}

public static void method01() throws IOException {
FileInputStream fis = new FileInputStream("E:\\itcast\\字节流复制图片.avi");
FileOutputStream fos = new FileOutputStream("F:\\JavaCode\\字节流复制图片.avi");
byte[] bys = new byte[1024];
int len;
while ((len = fis.read(bys)) != -1) {
fos.write(bys, 0, len);
}
fis.close();
fos.close();

fis.close();
fos.close();
}

public static void method02() throws IOException {
FileInputStream fis = new FileInputStream("E:\\itcast\\字节流复制图片.avi");
FileOutputStream fos = new FileOutputStream("F:\\JavaCode\\字节流复制图片.avi");
int by;
while ((by = fis.read()) != -1) {
System.out.println((char) by);
}
fis.close();
fos.close();

}

public static void method03() throws IOException {

BufferedInputStream bis = new BufferedInputStream(new FileInputStream("E:\\itcast\\字节流复制图片.avi"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("F:\\JavaCode\\字节流复制图片.avi"));

byte[] bys = new byte[1024];
int len;
while ((len = bis.read(bys)) != -1) {
bos.write(bys, 0, len);
}
bis.close();
bos.close();
}

public static void method04() throws IOException {

BufferedInputStream bis = new BufferedInputStream(new FileInputStream("E:\\itcast\\字节流复制图片.avi"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("F:\\JavaCode\\字节流复制图片.avi"));

int by;
while ((by = bis.read()) != -1) {
System.out.println((char) by);
}
bis.close();
bos.close();
}
}
posted @ 2022-03-24 21:20  刘品水  阅读(44)  评论(0编辑  收藏  举报