栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

复制视频四种实现方式(java)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

复制视频四种实现方式(java)

package com.company;

import java.io.*;
import java.nio.charset.StandardCharsets;

public class BufferedStreamDemo {
    public static void main(String[] args) throws IOException {
        //复制视频 四种方式
        long starttime = System.currentTimeMillis();
//        method1();  //字节流单字节复制   3049ms
//        method2(); //字节流字符数组   4ms
//        method3();  //字节缓冲流单字节  17ms
//        method4();  //字节缓冲里字符数组  2ms
        long endtime = System.currentTimeMillis();
        System.out.println("耗时:"+(endtime-starttime)+"ms");
    }
    public static void method1() throws IOException {
        FileInputStream fls = new FileInputStream("F:\test.mp4");
        FileOutputStream fos = new FileOutputStream("test.mp4");
        int len;
        while ((len= fls.read())!=-1){
            fos.write(len);
        }
        fls.close();
        fos.close();
    }
    public static void method2() throws IOException {
        FileInputStream fls = new FileInputStream("F:\test.mp4");
        FileOutputStream fos = new FileOutputStream("test1.mp4");
        byte[] b = new byte[1024];
        int len;
        while ((len= fls.read(b))!=-1){
            fos.write(b,0,len);
        }
        fls.close();
        fos.close();
    }
    public static void method3() throws IOException {
        FileInputStream fls = new FileInputStream("F:\test.mp4");
        FileOutputStream fos = new FileOutputStream("test2.mp4");
        BufferedInputStream bis = new BufferedInputStream(fls);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        int len;
        while ((len= bis.read())!=-1){
            bos.write(len);
        }
        bis.close();
        bos.close();
    }
    public static void method4() throws IOException {
        FileInputStream fls = new FileInputStream("F:\test.mp4");
        FileOutputStream fos = new FileOutputStream("test3.mp4");
        BufferedInputStream bis = new BufferedInputStream(fls);
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        byte[] b = new byte[1024];
        int len;
        while ((len= bis.read(b))!=-1){
            bos.write(b,0,len);
        }
        bis.close();
        bos.close();
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/755172.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号