I wrote a program in which I used the Scanner to read lines from log files and parse each line to find something important. It is important that I read every line of the log file. I wrote the following code snippet to scan each line
Scanner s = new Scanner(new File("Large.log"));
while(s.hasNextLine())
{
String line = s.nextLine();
}
The above code behaves in a weird way. It stops reading lines after a random number of lines [about 1 million lines]. I modified the above code to check the last line I read, and also checked the log file using Notepad ++. There are many lines left in this file after this particular line. I added another one System.out.println(s.hasNextLine())after the loop ends whileand it prints false.
However, if I try to do this using BufferedReader, the program works fine. Are there any restrictions on using I / O classes in Java?
source
share