I need to parse a csv file at work. Each line in the file is not very long, only a few hundred characters. I used the following code to read the file into memory.
def lines = []
new File( fileName ).eachLine { line -> lines.add( line ) }
When the number of lines is 10,000, the code works just fine. However, when I increase the number of lines to 100,000. I got this error:
java.lang.OutOfMemoryError: Java heap space
For 10,000 lines, the file size is about 7 MB, and ~70 MB for 100,000 lines. So, how would you solve this problem? I know increasing the heap size is a work-around. But are there any other solutions? Thank you in advance.