簡體   English   中英

java filereader以偏移量讀取

[英]java filereader read at offset

如何使用FileReader.read()讀取特定偏移量的字節?

FileReader fr = new FileReader(path);
char[] tmp = null;
fr.read(tmp, 11, 1);
n = tmp.toString();
n = Integer.parseInt(n,16);

盡管“路徑”中的文件有效且不為空,但此代碼返回nullpointerexception。 我打算在這里執行的操作是讀取該文件中的第11個字節。

使用BufferedReader.readLine()從文件讀取行可以在同一文件上很好地工作,但是我不知道如何從特定的偏移量開始獲取特定數量的字節。

read(char[] buf, int offset, int length) ,該偏移量是buf數組中的偏移量。 您需要跳過偏移字符。

FileReader fr = new FileReader(path);
int offset = 11;
fr.skip(11);
int c = fr.read();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM