I am having a bit of an issue where i am looping through a file that is excessively large (approximately 2gb). After about 5 minutes of running, i get the following issue: OutOfMemoryError: GC overhead limit exceeded.
My code is as follows which is relatively clean:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Organiser {
public static void main(String[] args) throws FileNotFoundException {
ArrayList<String> lines = new ArrayList<>();
String directory = "C:\\Users\\xxx\\Desktop\\Files\\combined";
Scanner fileIn = new Scanner(new File(directory + ".txt"));
while (fileIn.hasNextLine() == true) {
lines.add(fileIn.nextLine());
System.out.println("Reading.");
System.out.println("Reading..");
System.out.println("Reading...");
}
PrintWriter out = new PrintWriter(directory + "_ordered.txt");
Collections.sort(lines);
System.out.println("Ordering...");
for (String output : lines) {
out.println(output + "\n");
}
out.close();
System.out.println("Complete - See " + directory + "_ordered.txt");
}
}
Wondering how do i go about addressing this?