获取所有文件存储的属性
import java.io.IOException; import java.nio.file.FileStore; import java.nio.file.FileSystem; import java.nio.file.FileSystems; /* from 时代Java - nowjava.com */ public class Main { public static void main(String[] args) { // get information for all the stores in the default file system FileSystem fs = FileSystems.getDefault(); for (FileStore store : fs.getFileStores()) { try { long total_space = store.getTotalSpace() / 1024; long used_space = (store.getTotalSpace() - store.getUnallocatedSpace()) / 1024; /* 来 自* nowjava.com */ long available_space = store.getUsableSpace() / 1024; boolean is_read_only = store.isReadOnly(); System.out.println("--- " + store.name() + " --- " + store.type()); System.out.println("Total space: " + total_space); System.out.println("Used space: " + used_space); System.out.println(