I am trying to read a text file line by line with Java and searching for special lines with regex. The problem is my file is around 28MB. There are 198546 lines in it, but after around 110000 lines, my script doesn't search and finish the script without any exception. I think this is relates to the BufferedReader
size.
This is the one part of my code:
try {
BufferedReader br = new BufferedReader(new FileReader(logsArrayList.get(i).toString()));
String strLine;
number = 0;
while ((strLine = br.readLine()) != null) {
if ((lineNumber % 2) == 0) {
firstLine = strLine;
}
//control the regex
Matcher m = runRegex.matcher(strLine);
if (((lineNumber % 2) != 0) && m.find()) {
number++;
stringList.add(number + ") " + firstLine);
stringList.add(strLine);
logList.add(logsArrayList.get(i).toString());
logList.add(logsArrayList.get(i).toString());
}
publish(stringList.size());
lineNumber++;
}
br.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
So does anyone have any idea about why I am not able to read the whole file? Is it related to the BufferedReader
size, and if it is, how can I handle this problem?
Any help, ideas, or examples are appreciated.
EDIT: The script doesn't throw an exception.