跳的二进制文件的具体位置 [英] jump on specific location in binary file
问题描述
我有一个包含image.i必须在不同的位置跳文件中读取图像文件的二进制文件。到目前为止,我使用mark和reset方法但这些都不帮我,因为我想要的。
请有人帮助我一下,我,马上就真的thankful.and我使用输入流中读取文件。</ P>
您可以使用的 java.io.RandomAccessFile中来做到这一点。该方法寻求(长)和 getFilePointer() 将有助于跳转到不同的偏移量在文件中并回到原始偏移:
的RandomAccessFile F =新RandomAccessFile的(/我的/图像/文件,RW);//读取一些数据。长positionToJump = 10L;长origPos = f.getFilePointer(); //存储原始位置f.seek(positionToJump);
//现在你是在第10位,从这里开始阅读。//返回原来的位置
f.seek(origPos);
I have a binary file which contains image.i have to jump on different locations in file to read the image file. So far i am using mark and reset methods but these are not helping me as i want. please somebody help me about that i,ll be really thankful.and i am using Input Stream to read the file.
You can use the java.io.RandomAccessFile to do this. The methods seek(long) and getFilePointer() will help to jump to different offsets in the file and come back to original offsets:
RandomAccessFile f = new RandomAccessFile("/my/image/file", "rw");
// read some data.
long positionToJump = 10L;
long origPos = f.getFilePointer(); // store the original position
f.seek(positionToJump);
// now you are at position 10, start reading from here.
// go back to original position
f.seek(origPos);
这篇关于跳的二进制文件的具体位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!