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();
        }
    }
  • 相关阅读:
    数据库设计优化(一)--基础
    数据库设计--范式原则
    迭代器 与 foreach 的区别
    DBeaver中如何调整SQL编辑器的字体大小
    腾讯课堂下载回放视频
    超级美味的大盘鸡做法
    关闭或开启Win10系统的自动更新
    geoserver发布地图瓦片影像数据
    使用GeoServer发布Shapfile数据
    GeoServer下载与安装(Windows版)
  • 原文地址:https://www.cnblogs.com/lsswudi/p/11423078.html
Copyright © 2011-2022 走看看