字节流读写复制视频 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();
    }
}
相关推荐
倒流时光三十年8 分钟前
第一阶段 05 · Java 客户端查询类详解(Query / SearchCriteria / Response 与复杂拼接)
java·开发语言·python
rannn_1118 分钟前
【力扣hot100】哈希表专题——从两数之和到最长连续序列
java·算法·leetcode·哈希
观远数据9 分钟前
云原生BI的战略价值:不是技术选择,而是业务弹性的决定因素
java·人工智能·云原生
Full Stack Developme11 分钟前
Tomcat 设计原理
java·tomcat
心平气和量大福大17 分钟前
C#-WPF-控件-LiveChart图表-线性2(LineSeries)-数据绑定
开发语言·c#·wpf
gongzhxu19 分钟前
JetBrains IDEA开发环境搭建
java·ide·intellij-idea
lingran__24 分钟前
C++_stack和queue和priority_queue(容器适配器)
开发语言·c++
程序员三明治27 分钟前
【AI】RAG 生成阶段的最后一公里:Prompt 设计、幻觉抑制与引用对齐
java·人工智能·ai·大模型·llm·prompt·rag
Bug收容所30 分钟前
12305项目学习day5
java·spring boot·redis·mysql·spring·rocketmq
::呵呵哒::31 分钟前
java中SseEmitter
java·开发语言