Reputation: 5247
The Files.readAllLines javadoc states:
"Note that this method is intended for simple cases where it is convenient to read all lines in a single operation. It is not intended for reading in large files."
What constitutes a large file in this context? (I'm also curious about why it is not suggested for large files. Is it the actual I/O that is the problem, or is it the size of memory used to store the results of the reading?)
Upvotes: 5
Views: 913
Reputation: 34900
The problem is that this method reads all contents of the text file into the memory. If it is too large, you will simply receive java.lang.OutOfMemoryError
.
Yep, to clarify: large is a relative term. Its amount can not be specified as it depends on the free memory on the particular machine.
Upvotes: 6