I have a binary file which contains keys and after every key there is an image associated with it. I want to jump off different keys but could not find any method which changes the index positioning in input stream. I have seen the mark() method but it does not jump on different places.
Does anybody have any idea how to do that?
There’s a
long skip(long n)method that you may be able to use:As documented, you’re not guaranteed that
nbytes will be skipped, so doublecheck the returned value always. Note that this does not allow you to “skip backward”, but if it’smarkSupported(), you canreset()first and thenskipforward to an earlier position if you must.Other options
You may also use
java.io.RandomAccessFile, which as the name implies, permits random access with itsseek(long pos)method.You mentioned images, so if you are using Java Advanced Imaging, another possible option is
com.sun.media.jai.codec.FileSeekableStream, which is aSeekableStreamthat takes its input from aFileorRandomAccessFile. Note that this class is not a committed part of the JAI API. It may be removed or changed in future releases of JAI.