When parsing a large file I get the following error Caught: java.lang.OutOfMemoryError: Java heap space
How do you parse large files in Groovy without exceeding heap size?
example code that fails with large files…
import java.io.File
def inputFile = new File("c:/dev/test.txt")
inputFile.getText().eachLine{ it, i ->
... do something with each line
}
Ensure that the you’re iterating over the file in a way that doesn’t load the whole file into memory…
groovy -Xmx1024M myscript.groovySee also answer hereSee this page on the groovy mailing list for more info and further discussion
Code that works without a heap space error…