国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IO流_字節流四種方式復制MP4并測試效率

2019-11-10 17:10:59
字體:
來源:轉載
供稿:網友
package cn.itcast_06;import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;/* * 需求:把e://哥有老婆.mp4復制到當前項目目錄下的copy.mp4中 *  * 哥有老婆.mp4文件大小:65,258,338 字節 * 字節流四種方法復制文件: * 		基本字節流一次讀寫一個字節:共耗時:607844毫秒(607.844秒=10多分鐘) * 		基本字節流一次讀寫一個字節數組:共耗時:1042毫秒(1.042秒) * 		高效字節流一次讀寫一個字節:共耗時:5575毫秒(5.575秒) * 		高效字節流一次讀寫一個字節數組:共耗時:535毫秒(0.535秒) */public class CopyMp4Demo {	public static void main(String[] args) throws IOException {		long start = System.currentTimeMillis();		method1("e://哥有老婆.mp4", "copy1.mp4");		// method2("e://哥有老婆.mp4", "copy2.mp4");		// method3("e://哥有老婆.mp4", "copy3.mp4");		// method4("e://哥有老婆.mp4", "copy4.mp4");		long end = System.currentTimeMillis();		System.out.PRintln("共耗時:" + (end - start) + "毫秒");	}	/**	 * 基本字節流一次讀寫一個字節	 * 	 * @param srcString	 *            數據源	 * @param destString	 *            目的地	 */	public static void method1(String srcString, String destString)			throws IOException {		// 封裝數據源		FileInputStream fis = new FileInputStream(srcString);		// 封裝目的地		FileOutputStream fos = new FileOutputStream(destString);		// 復制數據		int len = 0;		while ((len = fis.read()) != -1) {			fos.write(len);		}		// 釋放資源		fos.close();		fis.close();	}	/**	 * 基本字節流一次讀寫一個字節數組	 * 	 * @param srcString	 *            數據源	 * @param destString	 *            目的地	 */	public static void method2(String srcString, String destString)			throws IOException {		// 封裝數據源		FileInputStream fis = new FileInputStream(srcString);		// 封裝目的地		FileOutputStream fos = new FileOutputStream(destString);		// 復制數據		byte[] bys = new byte[1024];		int len = 0;		while ((len = fis.read(bys)) != -1) {			fos.write(bys, 0, len);		}		// 釋放資源		fos.close();		fis.close();	}	/**	 * 高效字節流一次讀寫一個字節	 * 	 * @param srcString	 *            數據源	 * @param destString	 *            目的地	 */	public static void method3(String srcString, String destString)			throws IOException {		// 封裝數據源		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(				srcString));		// 封裝目的地		BufferedOutputStream bos = new BufferedOutputStream(				new FileOutputStream(destString));		// 復制數據		int len = 0;		while ((len = bis.read()) != -1) {			bos.write(len);		}		// 釋放資源		bos.close();		bis.close();	}	/**	 * 高效字節流一次讀寫一個字節數組	 * 	 * @param srcString	 *            數據源	 * @param destString	 *            目的地	 */	public static void method4(String srcString, String destString)			throws IOException {		// 封裝數據源		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(				srcString));		// 封裝目的地		BufferedOutputStream bos = new BufferedOutputStream(				new FileOutputStream(destString));		// 復制數據		byte[] bys = new byte[1024];		int len = 0;		while ((len = bis.read(bys)) != -1) {			bos.write(bys, 0, len);		}		// 釋放資源		bos.close();		bis.close();	}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 米脂县| 如皋市| 临清市| 邓州市| 红河县| 固镇县| 伊通| 闽侯县| 尖扎县| 专栏| 安福县| 松江区| 礼泉县| 井陉县| 涿州市| 新龙县| 铜鼓县| 韩城市| 山阳县| 玛纳斯县| 澳门| 临湘市| 玉龙| 南京市| 固始县| 建昌县| 阿勒泰市| 邵阳市| 木兰县| 武清区| 清镇市| 乌什县| 铁岭市| 甘洛县| 高淳县| 西峡县| 阜平县| 宁波市| 邓州市| 淮南市| 格尔木市|