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

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

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

2019-11-10 17:19:48
字體:
來源:轉載
供稿:網友
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();	}}
上一篇:Jdk安裝配置流程

下一篇:DFS學習筆記

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 台中县| 礼泉县| 米易县| 芜湖市| 志丹县| 景洪市| 平陆县| 鹤庆县| 方山县| 台州市| 虞城县| 黎平县| 绥德县| 达拉特旗| 临湘市| 新密市| 安阳市| 化州市| 通化市| 贵港市| 诏安县| 三江| 新泰市| 谢通门县| 嘉祥县| 寿阳县| 兴文县| 长岛县| 阿图什市| 景东| 宜章县| 克东县| 崇州市| 稻城县| 开阳县| 舒城县| 永康市| 泌阳县| 咸宁市| 嘉祥县| 永康市|