• 字节流复制视频的四种方式


    package com.io.liushuaishuai;
    /*
    四种方式复制视频  记录时间
    1 基本字节流一次一个字节
    2基本字节流一次一个字节数组
    3字节缓冲流1 基本字节流一次一个字节
    4字节缓冲流一次一个字节数组
     */
    
    import java.io.*;
    
    public class CopyMp4Demo {
        public static void main(String[] args) throws IOException {
            //记录开始时间
            long start = System.currentTimeMillis();
    
    
            //复制视频
            //method1();//共耗时30374ms
            //method2();//共耗时135ms
            //method3();//共耗时177ms
            //method4();//共耗时42ms
    
    
            //记录结束时间
            long end = System.currentTimeMillis();
    
            System.out.println("共耗时" + (end - start) + "ms");
        }
    
        public static void method1() throws IOException {
            FileInputStream fis = new FileInputStream("C:\壁纸\因为爱情.mp4");
            FileOutputStream fos = new FileOutputStream("myIOstream\qiaorenliang.mp4");
    
            int by;
            while ((by = fis.read()) != -1) {
                fos.write(by);
            }
            fos.close();
            fis.close();
        }
    
        public static void method2() throws IOException {
            FileInputStream fis = new FileInputStream("C:\壁纸\因为爱情.mp4");
            FileOutputStream fos = new FileOutputStream("myIOstream\qiaorenliang.mp4");
    
            byte[] bys = new byte[1024];
            int len;
            while ((len = fis.read(bys)) != -1) {
                fos.write(bys, 0, len);
            }
            fos.close();
            fis.close();
        }
    
        public static void method3() throws IOException {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\壁纸\因为爱情.mp4"));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("myIOstream\method3.mp4"));
    
            int i;
            while ((i = bis.read()) != -1) {
                bos.write(i);
            }
    
    
            bos.close();
            bis.close();
        }
    
        public static void method4() throws IOException {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\壁纸\因为爱情.mp4"));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("myIOstream\qiaorenliang.mp4"));
    
            byte[] bys = new byte[1024];
            int len;
            while ((len = bis.read(bys)) != -1) {
                bos.write(bys, 0, len);
            }
            bos.close();
            bis.close();
        }
    }
  • 相关阅读:
    在线捉鬼游戏开发之二
    在线捉鬼游戏开发之二
    在线捉鬼游戏开发之一
    Oxygen-Dapr.EshopSample 部署随记
    word2010 标题自动编号设置
    饿了么element 全屏加载中
    vue笔记
    那些骂鸿蒙的人,我想说……
    为什么我们要在 Sketch 中备份所有 Figma 设计
    好的设计要多分享,5款优秀在线原型设计案例
  • 原文地址:https://www.cnblogs.com/lsswudi/p/11423078.html
Copyright © 2020-2023  润新知