I want to copy the last 10MB of a possibly large file into another file. Ideally I would use FileInputStream, skip() and then read(). However I'm unsure if the performance of skip() will be bad. Is skip() typically implemented using a file seek underneath or does it actually read and discard data?
I know about RandomAccessFile but I'm interested in whether I could use FileInputStream in place of that (RandomAccessFile is annoying as the API is non-standard).
Depends on your JVM, but here's the source for
FileInputStream.skip()
for a recent openjdk:Looks like it's doing a
seek()
. However, I don't see whyRandomAccessFile
is non-standard. It's part of thejava.io
package and has been since 1.0.you will be interested with this LINK
it say that seek is faster than skip