views:

65

answers:

2

Is there an cross-platform way to determine the maximum file size of the host OS in Java?

+1  A: 

The largest file is surely no larger than the amount of free space, which you can get via

long FileSystemUtils.freeSpaceKb(String path)

from Apache Commons IO

On JDK 6, you can use File.getFreeSpace() to find the free space of the partition containing the file.

mdma
This is untrue. There are (legacy) filesystems which can't create files as large as the entire disk. FAT32 for example has a file size limitation of 4GB. NTFS (and most other 64bits file systems) in turn have a theoretical limit of 16EB, but the practical limit is much lesser as well, 2TB. Nowadays disks/array-of-disks are easily that big.
BalusC
d'oh of course. My bad. Rephrased the opening paragraph.
mdma
Might even be possible to create files greater than free space on compressing file systems...
Brian Knoblauch
+4  A: 

No, maximum file size is file system dependent. (you can see a comparison here). You can figure out the file system type using a platform specific manner (for example, mount on linux).

Omry