I've read the definition in the documentation and performed some searches on the Internet, but it is still not clear to me. What's the difference between getUsableSpace()
and getUnallocatedSpace()
in the FileStore
class?
From the FileStore class documentation
getUnallocatedSpace() Returns the number of unallocated bytes in the file store.
getUsableSpace() Returns the number of bytes available to this Java virtual machine on the file store.
So there is possibly more 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("************************************");
}
}
}
This is an excerpt of my output
************************************
tmpfs
Unallocated space: 206356480
Unused space: 206356480
************************************
/dev/sda6
Unallocated space: 1089933312
Unused space: 790126592
************************************
From peeking at the documentation, I would assume that getUsableSpace
is oriented toward the current java vm, while getUnallocatedSpace
refers to all unallocated space on the file store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With