字节流读写复制视频 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();
    }
}
相关推荐
骇客野人2 分钟前
SpringBoot电商购物车、结算、下单、库存方案设计与落地实施步骤
java·spring boot·后端
asdzx679 分钟前
Python 实现 PDF 文本查找与高亮标注
开发语言·python·pdf
zander25812 分钟前
LeetCode 1143. 最长公共子序列
开发语言·python·算法
Sumerking14 分钟前
llc_control.c 专项评审(v3 更新版)
c语言·开发语言·算法·obc
哪 吒21 分钟前
华为OD机试 - 云服务安全策略最优选择 - 深度优先搜索DFS(Java 新系统 200分)
java·华为od·深度优先
拒绝内耗。23 分钟前
程序员学架构(一):一张图看懂 Java 后端架构:一个请求怎样从手机到数据库?
java·智能手机·架构
棣廷24 分钟前
初识Python面向对象
java·开发语言
用户31268748772029 分钟前
ThreadLocal 到底会不会内存泄漏?源码级拆解 + 线程池陷阱
java
研☆香30 分钟前
js中 onload 事件的用法
开发语言·javascript·ecmascript
珍珠先生33 分钟前
P11 · MySQL 驱动版本过旧:Client does not support authentication protocol
java