Is there a limit on the size of a file that Java can open?

Tim Rohaly

With the exception of RandomAccessFile, all I/O in Java is done using streams. With a stream, data is read or written on-the-fly, without buffering (unless you buffer explicitly via a buffered stream or other means). Because only the portion of the data you're reading or writing is in memory, the size of the file is irrelevant - Java sets no limit other than the implicit limit imposed by the size of a long integer which is used as the file length. This is larger than the file size allowed by most file systems.

Contrary to what you might think, creating a File object does not read the contents of that file into memory - it merely serves as a container for a file descriptor and meta-information about the file.

The specification for RandomAccessFile does not mandate any particular implementation, so it is possible that some implementations do have a limit on the size of file they can open. But most implementations probably use some sort of stream internally, so the limitations are as described above.