如何从某个偏移量读取文件 [英] How to read a file from a certain offset

查看:179
本文介绍了如何从某个偏移量读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我试图打开一个文件,只是从一个偏移量读取一定的长度!
我读了这个主题:
如何从Java中的文件中使用特定行号读取特定行?
在那里它表示不可能读取某一行读之前的行,但我想知道的字节!

  FileReader location = new FileReader(file); 
BufferedReader inputFile = new BufferedReader(location);
//从字节读取1000到2000
//像这样
inputFile.read(1000,2000);

是否可以读取已知偏移量的某些字节?

解决方案

RandomAccessFile 公开了一个函数:

$ p $ find $($ $ $ $ $ $)从该文件的开始处开始测量下一次读取或写入的偏移量。


Hey I'm trying to open a file and read just from an offset for a certain length! I read this topic: How to read a specific line using the specific line number from a file in Java? in there it said that it's not to possible read a certain line without reading the lines before, but I'm wondering about bytes!

FileReader location = new FileReader(file);
BufferedReader inputFile = new BufferedReader(location);
// Read from bytes 1000 to 2000
// Something like this
inputFile.read(1000,2000);

Is it possible to read certain bytes from a known offset?

解决方案

RandomAccessFile exposes a function:

seek(long pos) 
          Sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs.

这篇关于如何从某个偏移量读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆