字节流读写复制视频 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();
    }
}
相关推荐
paopaokaka_luck9 分钟前
滑雪场管理系统(AI智能助手流式对话,ECharts 运营数据分析、教练、雪具与场地一体化预约,钱包支付退款、订单核销与服务评价)
java·人工智能·spring boot·网络协议·数据分析·echarts
阿里嘎多学长17 分钟前
2026-10-12 GitHub 热点项目精选
开发语言·程序员·github·代码托管
Wang's Blog36 分钟前
Java 项目实战: 交友项目 - Dubbo 的内部结构与一次调用的完整链路
java·dubbo
Wang's Blog41 分钟前
Java 项目实战: 交友项目 - Dubbo 入门引导
java·dubbo·交友
wangchunyu1141 小时前
Python 数据可视化实战入门教程
开发语言·python·信息可视化
蜗牛互联网1 小时前
Python Agent工具调用的白名单、参数校验与审批门禁
java·服务器·前端·人工智能·后端·python
SL_staff1 小时前
当规则引擎开始‘懂业务’:JVS-Rules金融风控四大原生能力拆解
java·python·全栈
Shaoshing2 小时前
前缀和与差分
java·数据结构·算法·前缀和·差分
dd聊技术2 小时前
Prompt 从代码常量搬进数据库:改一句话,不用再发一次版
java·后端
ly76892 小时前
Spring Data MongoDB 批量写入实践:BulkOperations 批大小与写关注权衡
java·mongodb·spring·批量写入·bulkoperations·写关注·mongotemplate