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(); } }
原文地址:https://www.cnblogs.com/lsswudi/p/11423078.html
时间: 2024-10-11 02:16:52