import java.io.File;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Iterator;
public class DiskSpace {
public static void main(String[] args) {
FileSystem fs = FileSystems.getDefault();
Iterable drives = fs.getRootDirectories();
Iterator path = drives.iterator();
while(path.hasNext()){
Path p = path.next();
String drive = p.toString();
System.out.println(drive);
File f = new File(drive);
float freeSpace = f.getFreeSpace();
float totalSpace = f.getTotalSpace();
if(totalSpace>0){
float percentFree = (freeSpace/totalSpace)*100;
System.out.println(drive + "---- " +freeSpace + "------ " + totalSpace + "---------- " + percentFree);
}
}
}
}
A blog that every Java developer can refer to. Besides java development we do post on some extra language features as we come across some good technical stuff.
Showing posts with label File. Show all posts
Showing posts with label File. Show all posts
Wednesday, 20 August 2014
How to find disk space utilization using Java?
Subscribe to:
Posts (Atom)