简体   繁体   中英

Read specific bytes from RandomAccessFile using FileChannel : Java

I have a RandomAccessFile and its FileChannel. What I'm trying to do is read a specific section of the bytes from said file; however, while looking over the FileChannel read methods, I didn't see overloads that would help with what I'm trying to do, only methods which would read the entire content, or read content to a specific position in the buffer that the read method takes in. Is there a method that I'm missing that will help me accomplish my goal of reading a specific chunk of bytes, or will I need to read in the entire channel into the buffer and then parse out the section somehow?

您可以使用FileChannel#position(long)转到文件中的特定位置,然后read所需大小的缓冲区。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM