字节流读写复制视频 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();
    }
}
相关推荐
Jul1en_16 分钟前
【Java 脚手架】封装通用工具类-1
java·spring boot·分布式·spring·spring cloud
mlidongfeng41 分钟前
[AI][C++26] SIMD 编程模型思考
开发语言·c++·人工智能
j7~42 分钟前
【Linux】二十七.线程篇四《Linux多线程编程:线程互斥(互斥量的底层到封装)、线程安全和冲入、死锁》---详解
linux·开发语言·c++·线程安全·死锁·线程互斥·重入
关于不上作者榜就原神启动那件事1 小时前
从 MDC 到 Agent:我手搓的文档路由协议,在 Spring AI Alibaba 里找到了正式实现
java·人工智能·spring·ai·agent
刘名喜1 小时前
第09篇-协程基础-Kotlin异步编程
开发语言·kotlin·springboot
其实防守也摸鱼1 小时前
HackBar 工具完全指南:信息探测、漏洞验证与安全测试实战
开发语言·人工智能·学习·安全·网络安全·安全威胁分析·安全性测试
亦暖筑序1 小时前
重新认识 AgentScope-Java 2.0:ReActAgent 负责推理,HarnessAgent 负责运行
java·后端·agent
会博通·代码搬运工1 小时前
会博通API对接实战:工程企业文档分布式采集系统的技术实现与Python SDK详解
开发语言·分布式·python·线性代数·矩阵·架构·电子档案合规
木井巳1 小时前
【DFS解决floodfill算法】岛屿的最大面积
java·算法·leetcode·深度优先
运维大师1 小时前
【K8S 运维实战】34-多集群管理Karmada
java·运维·kubernetes