gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 20:34:25 24 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/9671126/

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