I need an InputStream
to read from some nonzero offset in a File
. Which is the more performant way to get and position the stream,
InputStream in = new FileInputStream(file);
in.skip(n);
or
RandomAccessFile raf = new RandomAccessFile(file, "r");
InputStream in = Channels.newInputStream(raf.getChannel().position(n));
Or is there a better way that you'd suggest?
Only one stream will be pulled from the file, so there's no benefit from reusing the RandomAccessFile
.