字节流读写复制视频 JAVA

四种方式实现复制视频,并记录每种复制方式的耗时

java 复制代码
import java.io.*;

//四种方式实现复制视频,并记录每种复制方式的耗时
/*
  1、基本字节流一次读写一个字节          共耗时:10809毫秒
  2、基本字节流一次读写一个字节数组       共耗时:14毫秒
  3、字节缓冲流一次读写一个字节          共耗时:14毫秒
  4、字节缓冲流一次读写一个字节数组       共耗时:6毫秒
*/
public class FileDemo_11 {
    public static void main(String[] args) throws IOException {
        //记录时间
        long startTime = System.currentTimeMillis();

        //method1();
        //method2();
        //method3();
        method4();


        long endTime = System.currentTimeMillis();
        System.out.println("共耗时:"+(endTime-startTime)+"毫秒");
    }

    public static void method1() throws IOException{
        FileInputStream fis = new FileInputStream("C:\\Users\\gzh\\Videos\\Captures\\图书管理系统.mp4");
        FileOutputStream fos = new FileOutputStream("图书管理系统.mp4");
        int by;
        while((by=fis.read())!=-1)
            fos.write(by);

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

    public static void method2() throws IOException{
        FileInputStream fis = new FileInputStream("C:\\Users\\gzh\\Videos\\Captures\\图书管理系统.mp4");
        FileOutputStream fos = new FileOutputStream("图书管理系统.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 method3() throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\gzh\\Videos\\Captures\\图书管理系统.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("图书管理系统.mp4"));

        int by;
        while((by=bis.read())!=-1){
            bos.write(by);
        }
        bis.close();
        bos.close();
    }

    public static void method4() throws IOException{
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\gzh\\Videos\\Captures\\图书管理系统.mp4"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("图书管理系统.mp4"));

        byte[] bys = new byte[1024];
        int len;
        while((len=bis.read(bys))!=-1){
            bos.write(bys,0,len);
        }
        bis.close();
        bos.close();
    }
}
相关推荐
じ☆ve 清风°4 分钟前
JavaScript 原型与原型链:深入理解 __proto__ 和 prototype 的由来与关系
开发语言·javascript·原型模式
BillKu5 分钟前
Java + Spring Boot + Mybatis 实现批量插入
java·spring boot·mybatis
YuTaoShao7 分钟前
Java八股文——集合「Map篇」
java
有梦想的攻城狮2 小时前
maven中的maven-antrun-plugin插件详解
java·maven·插件·antrun
_r0bin_5 小时前
前端面试准备-7
开发语言·前端·javascript·fetch·跨域·class
zhang98800005 小时前
JavaScript 核心原理深度解析-不停留于表面的VUE等的使用!
开发语言·javascript·vue.js
硅的褶皱6 小时前
对比分析LinkedBlockingQueue和SynchronousQueue
java·并发编程
MoFe16 小时前
【.net core】天地图坐标转换为高德地图坐标(WGS84 坐标转 GCJ02 坐标)
java·前端·.netcore
季鸢6 小时前
Java设计模式之观察者模式详解
java·观察者模式·设计模式
Fanxt_Ja6 小时前
【JVM】三色标记法原理
java·开发语言·jvm·算法