Get free space, total space, usable space

ReturnMethodSummary
longgetFreeSpace()Returns the number of unallocated bytes in the partition named by this abstract path name.
longgetTotalSpace()Returns the size of the partition named by this abstract pathname.
longgetUsableSpace()Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.

import java.io.File;

public class Main {

  public static void main(String[] args) {
    File aFile = new File("c:/");
    System.out.println(aFile.getFreeSpace());
    System.out.println(aFile.getTotalSpace());
    System.out.println(aFile.getUsableSpace());
  }
}

The output:


12283260928
79990812672
12283260928
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.