Monday, 25 April 2016

How to get total of free disk space in your partition or volume ?


To get total disk space (in bytes) : getTotalSpace()
To get free disk space including unallocated space (in bytes) : getFreeSpace()
To get free disk space that is usable by user in the VM (in bytes) : getUsableSpace()

Example
File file = new File("c:");

long totalSpace = file.getTotalSpace();
System.out.println("Total size : " + totalSpace + " bytes");
System.out.println("Total size : " + totalSpace /1024 /1024 + " mb");

long usableSpace = file.getUsableSpace();
System.out.println("Space free : " + usableSpace + " bytes");


System.out.println("Space free : " + usableSpace /1024 /1024 + " mb");

long freeSpace = file.getFreeSpace();
System.out.println("Space free : " + freeSpace + " bytes");
System.out.println("Space free : " + freeSpace /1024 /1024 + " mb");

No comments:

Post a Comment

Note: only a member of this blog may post a comment.