What is the difference between getUsableSpace and getUnallocatedSpace of class FileStore

I read the definition in the documentation and completed some of the Internet searches, but it’s still not clear to me. What is the difference between getUsableSpace()and getUnallocatedSpace()in class FileStore?

+6
source share
3 answers

From the FileStore Class Documentation

getUnallocatedSpace () Returns the number of unallocated bytes in the file vault.

getUsableSpace () Returns the number of bytes available for this Java virtual machine in the file vault.

Thus, perhaps there is still unallocated space than usable space.

You can test it with the following code snippet

import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.FileSystems;

public class TestFileStore {
    public static void main(String[] args) throws IOException {
        for (FileStore fileStore : FileSystems.getDefault().getFileStores()) {
            System.out.println(fileStore.name());
            System.out.println("Unallocated space: " + fileStore.getUnallocatedSpace());
            System.out.println("Unused space: " + fileStore.getUsableSpace());
            System.out.println("************************************");
        }
    }
}

************************************
tmpfs
Unallocated space: 206356480
Unused space: 206356480
************************************
/dev/sda6
Unallocated space: 1089933312
Unused space: 790126592
************************************
+2

, getUsableSpace java vm, getUnallocatedSpace .

0

getUsableSpace: Returns the number of bytes available for this Java virtual machine in the file vault. in the file vault.

getUnallocatedSpace: returns the number of unallocated bytes in the file vault.

Note that the bytes available for this JVM may be less than unallocated space for write permissions and other operating system restrictions.

0
source

All Articles