I could not point out exact difference between getFreeSpace()
and getUsableSpace()
method of File
class. When i run following code
The javadoc of getUsableSpace()
says:
When possible, this method checks for write permissions and other operating system restrictions and will therefore usually provide a more accurate estimate of how much new data can actually be written than getFreeSpace().
So we should choose getUsableSpace
in most cases.
update:
notice below reported bug, in a very large disk the size of the space may exceed the limits of long
type and return a negative value:
JDK-8179320 : File getUsableSpace() returns a negative number on very large file system