Name: krC82822 Date: 05/03/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
When the skip(long) method is used from any position in the stream with a skip
value that is larger than the available bytes in the stream, the skip method
skips beyond EOF and returns the same value that was given to it.
See code below.
There are several related bugs on the Bug Parade.
However, # 4178064, the closest match,
appears to restrict the problem to [what happens]
once the EOF has already been reached.
The scope of the problem is larger than that.
Also of note: the workaround for that bug
does not help in the situation that I demonstrate.
I think it would be helpful for others to have access to
the workaround I have provided.
public class TestFileInputStream
public static void main(String argv)
//Open a FileInputStream for a "small" file
FileInputStream f = new FileInputStream("c:\\Test.txt");
//Try skipping way past the end of file.
//This call should return the number of bytes in the file
//but instead returns 500000, which according to the contract
//for InputStream, may/should return less if the end of file is
long skipped = f.skip(500000);
System.out.println("Skipped " + skipped + " bytes");
(Review ID: 123668)