Name: dbT83986 Date: 02/17/99
java.io.LineNumberReader.skip() does not correctly update
the number of lines read.
A previous bug (4134311) mentionned this after a certain size, but in fact
it fails for all sizes (I tried it on a textfile of 187 bytes
and it returned a linecount of 260!).
also, note that skip returns and uses a long while
getLineNumber and setLineNumber return and use an int.
A large file containing many empty lines could cause an error.
here is a snippet demonstrating the error:
package test_LineReader;
import java.io.*;
public class CountIt
{
public static void main (String[] argv)
{
LineNumberReader thisReader = null;
// PushbackLineReader thisReader = null;
File inputFile = null;
String currentLine = null;
int lineNumber = 0;
try
{
inputFile = new File (argv[0]);
thisReader = new LineNumberReader (new FileReader(inputFile ));
// thisReader = new PushbackLineReader (new FileReader(inputFile ));
System.out.println ("This file has " +
inputFile.length() +
" bytes."
);
thisReader.skip (inputFile.length() -1);
System.out.println ("This file has " +
thisReader.getLineNumber() +
" lines."
);
}
catch(Exception ex)
{
System.out.println (ex.toString());
}
} // main
}
(Review ID: 53289)
======================================================================
- relates to
-
JDK-4063511 java.io.LineNumberReader class get wrong lineNumber while skip out of file
-
- Closed
-