I want to print each line from a huge textfile (more than 600 000 MB).
But when I try the code below I get "...OutOfMemoryError: Java heap space" right before reaching line number 1 000 000.
Is there a better way to handle the input rather than FileReader and LineNumberReader?
FileReader fReader = new FileReader(new File("C:/huge_file.txt"));
LineNumberReader lnReader = new LineNumberReader(fReader);
String line = "";
while ((line = lnReader.readLine()) != null) {
System.out.println(lnReader.getLineNumber() + ": " + line);
}
fReader.close();
lnReader.close();
Thanks in advance!
Thanks all for your answers!
I finally found the memory leak, an unused java class instance which duplicated it self for each row iteration. In other words, it had nothing to do with the file loading part.