I can only think of two scenarios in which that code could result in an OOME:
If the
file
directory has a very large number of elements, thenfile.listFiles()
could create a very large array ofFile
objects.If one of the input files includes a line that is very long, then
CSVFile.readLine()
could use a lot of memory in the process of reading it. (Up to 6 times the number of bytes in the line.)
The simplest approach to solving both of these issues is to increase the Java heap size using the -Xmx
JVM option.
I can see no reason why your use of a PrintWriter
would be the cause of the problem.