嘿,我正在尝试打开文件,仅从偏移量读取一定长度!我阅读了以下主题: 如何使用Java中的文件中的特定行号读取特定行? 在那儿,它说在不读取之前就不可能读取某行,但是我想知道字节!
FileReader location = new FileReader(file); BufferedReader inputFile = new BufferedReader(location); // Read from bytes 1000 to 2000 // Something like this inputFile.read(1000,2000);
是否可以从已知偏移量读取某些字节?
RandomAccessFile提供一个功能:
seek(long pos) Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.