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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用RandomAccessFile和BufferedReader加速文件讀取

使用RandomAccessFile和BufferedReader加速文件讀取

九州編程 2019-04-20 15:15:27
我必須 :-逐行讀取大文本文件。記下每行讀取后的文件指針位置。如果運(yùn)行時(shí)間大于30秒,則停止讀取文件。從新進(jìn)程中的最后一個(gè)文件指針恢復(fù)。我在做什么 :使用RandomAccessFile.getFilePointer()來(lái)記錄文件指針。將RandomAccessFile包裝到另一個(gè)BufferedReader中,以根據(jù)此答案加快文件讀取過(guò)程。當(dāng)時(shí)間大于30秒時(shí),我停止讀取文件。使用新的RandomAccessFile重新啟動(dòng)進(jìn)程并使用RandomAccessFile.seek方法將文件指針移動(dòng)到我離開(kāi)的位置。問(wèn)題:當(dāng)我正在閱讀包裹在RandomAccessFile中的BufferedReader時(shí),似乎文件指針在一次調(diào)用BufferedReader.readLine()時(shí)正在向前移動(dòng)。但是,如果我直接使用RandomAccessFile.readLine(),文件指針正向一步一步正向移動(dòng)。使用BufferedReader作為包裝器:    RandomAccessFile randomAccessFile = new RandomAccessFile("mybigfile.txt", "r");BufferedReader brRafReader = new BufferedReader     (new FileReader(randomAccessFile.getFD()));while((line = brRafReader.readLine()) != null) {     System.out.println(line+", Position : "+randomAccessFile.getFilePointer());}輸出:Line goes here, Position : 13040Line goes here, Position : 13040Line goes here, Position : 13040Line goes here, Position : 13040使用Direct RandomAccessFile.readLine    RandomAccessFile randomAccessFile = new RandomAccessFile("mybigfile.txt", "r");while((line = randomAccessFile.readLine()) != null) {     System.out.println(line+", Position : "+randomAccessFile.getFilePointer());}輸出:(這是預(yù)期的。每次調(diào)用readline時(shí)文件指針都正常移動(dòng))Line goes here, Position : 11011Line goes here, Position : 11089Line goes here, Position : 12090Line goes here, Position : 13040誰(shuí)能告訴我,我在這做什么錯(cuò)?有什么辦法可以使用RandomAccessFile加快閱讀過(guò)程嗎?
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 1841 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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