Java.util.Scanner does not work when reading large files

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();
    //do the processing of the log line
}

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?

+3
source share
2 answers

It sounds like big file support with your specific JVM implementation. For many standard file I / O operations for working with files> 4 GB on 32-bit operating systems, a problem often occurs. Usually, alternative versions of the file APIs explicitly support large files, but the person implementing the JVM will need to remember them. Out of curiosity, which OS are you using and 64-bit?

+3
source

, 50 , , 5 . , .

:

  • , , ?
  • , , /.
0

Source: https://habr.com/ru/post/1791791/


All Articles