I have to read an 8GB .log file to extract some pieces of information, but in that file, there are many lines that I don't need. Some of them are so long (more than 15,000,000 characters) that it slows the code, and it takes more than a day to read it all (without doing any other operation).
I need something that reads the first word in the line and if it starts with a specific sequence skips it without reading any characters.
I tried with skip
, but since it says it skips the matched pattern, it has to read the line to match it. In that way, it still reads an extremely long sequence of characters which makes the program too slow.
This is the code I've done so far:
File logFile = new File(logFilePath);
Scanner fileScanner = new Scanner(logFile);
while (fileScanner.hasNextLine()) {
String currentLine = fileScanner.next();
if (currentLine.equals("messaggio:")) {
fileScanner.skip("\n"); // This is where I want to skip the line WITHOUT reading it
}
else {
// Other code
}
}
fileScanner.close();