zoukankan      html  css  js  c++  java
  • 字节流复制视频的四种方式

    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();
        }
    }
  • 相关阅读:
    js--事件
    js之table操作
    2019年目标
    history.back返回后输入框值丢失问题
    C++ 工程师养成 每日一题4.5 (迭代器遍历)
    C++ 工程师养成 每日一题fourth (reverse的使用)
    C++ 工程师养成 每日一题third (子数列排序)
    C++工程师养成 每日一题(string使用)
    C++工程师养成 每日一题(vector使用)
    运算符优先级
  • 原文地址:https://www.cnblogs.com/lsswudi/p/11423078.html
Copyright © 2011-2022 走看看