国产探花免费观看_亚洲丰满少妇自慰呻吟_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();	}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 横山县| 永胜县| 江津市| 长治县| 东城区| 分宜县| 平安县| 民县| 文安县| 石景山区| 股票| 邻水| 六盘水市| 鸡泽县| 长葛市| 梅州市| 陈巴尔虎旗| 桦甸市| 新丰县| 芒康县| 德州市| 连平县| 秭归县| 西青区| 泊头市| 虞城县| 台中县| 常熟市| 定边县| 合川市| 无棣县| 堆龙德庆县| 淮阳县| 达孜县| 南平市| 资阳市| 绥德县| 石家庄市| 保定市| 乃东县| 双柏县|