第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

對1.09G文件操作時間,談及個人理解

public static void copyFlie(File srcFile ,File destFile) throws IOException {

if(!srcFile.exists()) {

throw new IllegalArgumentException("目標(biāo)文件:"+srcFile +" 不存在");

}

if(!srcFile.isFile()) {

throw new IllegalArgumentException(srcFile+" 不是文件");

}

FileInputStream in = new FileInputStream(srcFile);

FileOutputStream out = new FileOutputStream(destFile);

byte[] buf = new byte[8*1024];

int b;

while((b = in.read(buf, 0, buf.length))!=-1) {

out.write(buf, 0, b);

}

in.close();

out.close();

}

/**

* 進(jìn)行文件的拷貝,利用帶緩存的字節(jié)流

*?

* @param srcFile

* @param destFile

*/

public static void copyByBuffer(File srcFile ,File destFile) throws IOException{

if(!srcFile.exists()) {

throw new IllegalArgumentException("目標(biāo)文件:"+srcFile +" 不存在");

}

if(!srcFile.isFile()) {

throw new IllegalArgumentException(srcFile+" 不是文件");

}

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));

byte[] buf = new byte[8*102];

int c;

while((c=bis.read(buf , 0 ,buf.length))!=-1) {

bos.write(buf,0,c);

bos.flush();//刷新緩沖區(qū)

}

bis.close();

bos.close();

}


對1.09G文件的操作,進(jìn)行五組數(shù)據(jù)對比,copyFlie平均用時14093,copyByBuffer當(dāng)flush在循環(huán)外平均用時13971

由于每次讀取時間不確定,有的copyfile快于copybybuffere,有的相反,所以感覺速度不相上下。當(dāng)copybybuffere采用單字節(jié)的時候,時間不可想象,太長了,如果flush在循環(huán)內(nèi)部時間也會過長,沒有做對比

正在回答

1 回答

這是為啥。。

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

對1.09G文件操作時間,談及個人理解

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號