控制台程序,列出存储在系统中的文件的详细信息
import java.nio.file.FileStore;
import java.nio.file.FileSystems;
import java.nio.file.FileSystem;
import java.io.IOException; public class GetFileStores{ public static void main(String[] args){
FileSystem fileSystem=FileSystems.getDefault();
Iterable<FileStore> stores=fileSystem.getFileStores();
long gigabyte=1_073_741_824L;
for(FileStore store:stores){
try{
System.out.format(
"\nStore:%-20s %-5s Capacity:%5dgb Unallocated:%6dgb",
store.name(),
store.type(),
store.getTotalSpace()/gigabyte,
store.getUnallocatedSpace()/gigabyte);
}catch(IOException e){
e.printStackTrace();
}
}
}
}