字节流复制视频,并对比字节流复制视频和字节缓冲流复制视频的耗时

import java.io.*;

public class BufferStreamDome01 {
public static void main(String[] args) throws IOException {
long kaishi = System.currentTimeMillis();
// mothed01();
// mothed02(); //共用时:414毫秒
// mothed03(); //共用时:1821毫秒
mothed04(); //共用时:110毫秒
long jieshu = System.currentTimeMillis();
System.out.println(“共用时:” +(jieshu-kaishi)+“毫秒”);
// System.out.println(“1”);
}
//字节缓冲流一次读写一个数组
public static void mothed04() throws IOException{
BufferedInputStream bis =
new BufferedInputStream(
new FileInputStream(“D:\IDEA\src\JavaHeiMa02\src\字节流ByteStream\字节缓冲流\01_字节缓冲流.mp4”));
BufferedOutputStream bos =
new BufferedOutputStream(
new FileOutputStream(“D:\IDEA\src\JavaHeiMa02\src\字节流ByteStream\字节缓冲流\字节流复制视频\01_字节缓冲流.mp4”) );
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 mothed03() throws IOException{
    BufferedInputStream bis =
            new BufferedInputStream(
                    new FileInputStream("D:\\IDEA\\src\\JavaHeiMa02\\src\\字节流ByteStream\\字节缓冲流\\01_字节缓冲流.mp4"));
    BufferedOutputStream bos =
            new BufferedOutputStream(
                    new FileOutputStream("D:\\IDEA\\src\\JavaHeiMa02\\src\\字节流ByteStream\\字节缓冲流\\字节流复制视频\\01_字节缓冲流.mp4") );
    int by;
    while ((by=bis.read())!=-1){
        bos.write(by);
    }
    bis.close();
    bos.close();
}

// 字节流一次读写一个数组
public static void mothed02() throws IOException {
FileInputStream fis =
new FileInputStream(“D:\IDEA\src\JavaHeiMa02\src\字节流ByteStream\字节缓冲流\01_字节缓冲流.mp4”);
FileOutputStream fos =
new FileOutputStream(“D:\IDEA\src\JavaHeiMa02\src\字节流ByteStream\字节缓冲流\字节流复制视频\01_字节缓冲流.mp4”);
byte[] bys = new byte[1024];
int len;
while ((len=fis.read(bys))!=-1){
fos.write(bys,0,len);
}

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

//字节流一次读写一个字节
public static void mothed01() throws IOException {
    FileInputStream fis =
            new FileInputStream("D:\\IDEA\\src\\JavaHeiMa02\\src\\字节流ByteStream\\字节缓冲流\\01_字节缓冲流.mp4");
    FileOutputStream fos =
            new FileOutputStream("D:\\IDEA\\src\\JavaHeiMa02\\src\\字节流ByteStream\\字节缓冲流\\字节流复制视频\\01_字节缓冲流.mp4");
    int by;
    while ((by=fis.read())!=-1){
        fos.write(by);
    }
    fis.close();
    fos.close();
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值