Difference between getFreespace() and getUsableSpace of File

后端 未结 3 975
慢半拍i
慢半拍i 2021-01-03 23:53

I could not point out exact difference between getFreeSpace() and getUsableSpace() method of File class. When i run following code

3条回答
  •  甜味超标
    2021-01-04 00:53

    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

提交回复
热议问题