看了文档中的定义,在网上搜索了一下,还是不太清楚。 FileStore
类中的 getUsableSpace()
和 getUnallocatedSpace()
有什么区别?
最佳答案
来自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.
所以未分配空间可能比可用空间多。
您可以使用以下代码片段对其进行测试
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
************************************
关于java - FileStore类的getUsableSpace和getUnallocatedSpace有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16302348/