gpt4 book ai didi

java - Java中如何从某个偏移量处读取文件?

转载 作者:太空宇宙 更新时间:2023-11-04 12:00:25 26 4
gpt4 key购买 nike

嘿,我正在尝试打开一个文件并仅从偏移量读取特定长度!我读过这个主题: How to read a specific line using the specific line number from a file in 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.

关于java - Java中如何从某个偏移量处读取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40961385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com