下面列出了java.nio.file.FileStore#getUnallocatedSpace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Space get() throws BackgroundException {
final Path home = new DefaultHomeFinderService(session).find();
try {
final FileStore store = Files.getFileStore(session.toPath(home));
return new Space(store.getTotalSpace() - store.getUnallocatedSpace(), store.getUnallocatedSpace());
}
catch(IOException e) {
throw new LocalExceptionMappingService().map("Failure to read attributes of {0}", e, home);
}
}
private Double freeSpace ()
{
try
{
final String base = System.getProperty ( SYSPROP_STORAGE_BASE );
final Path p = Paths.get ( base );
final FileStore store = Files.getFileStore ( p );
return (double)store.getUnallocatedSpace () / (double)store.getTotalSpace ();
}
catch ( final Exception e )
{
return null;
}
}
public long unallocatedBytes() throws IOException {
Iterable<FileStore> fileStores = localFileSystem.getFileStores();
long totalUsableSpace = 0l;
for(FileStore fs:fileStores){
totalUsableSpace+=fs.getUnallocatedSpace();
}
return totalUsableSpace;
}
@Test
public void get_used_space_nio () throws IOException {
FileStore store = Files.getFileStore(source);
long usedSpace = (store.getTotalSpace() -
store.getUnallocatedSpace()) / 1024;
assertTrue(usedSpace > 0);
}