import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class DiskSpaceNIO {
public static void main(String[] args) throws IOException {
Path path = Paths.get("/"); // Root directory
FileStore store = Files.getFileStore(path);
long totalSpace = store.getTotalSpace();
long unallocatedSpace = store.getUnallocatedSpace();
long usableSpace = store.getUsableSpace();
System.out.println("Total space: " + totalSpace + " bytes");
System.out.println("Unallocated space: " + unallocatedSpace + " bytes");
System.out.println("Usable space: " + usableSpace + " bytes");
}
}
No comments:
Post a Comment