I have been trying to read an XML file which is of 2GB. I have followed different methods to read it but each of those methods give OutOfMemoryError
I even tried to increase heapsize max to 4GB and min 2GB heap size in eclispe but still problem persists. How can i resolve this problem? I don't want to use any third party libaray.
Following is the code that i have tried so far
String str = new String(Files.readAllBytes(Paths.get(pathname)),
StandardCharsets.UTF_8);
and
try(Scanner scanner = new Scanner(new File(pathname))) {
while ( scanner.hasNextLine() ) {
String line = scanner.nextLine();
}
}