I\'m trying to read/write a huge text file. But when I try to do that I get the error:
Exception in thread \"main\" java.lang.OutOfMemoryError: Java heap space
Don't try to read large files into memory. They don't fit. Find a way of processing the file a line at a time, or a record at a time, or a chunk at a time. I can't see any reason here why you can't do that.
Calling File.exists()
and File.createNewFile()
immediately before constructing a FileWriter
around the same File
is a complete waste of time.