How to use getFreeSpace(), getTotalSpace() and getUsableSpace()?

long getFreeSpace() Returns the number of unallocated bytes in the partition named by this abstract path name.
long getTotalSpace() Returns the size of the partition named by this abstract pathname.
long getUsableSpace() Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.

package com.nourit.javaIO;

import java.io.File;

public class GetSpaceExample {

  public static void main(String[] args) {
    File file = new File("D:/");
    System.out.println(file.getFreeSpace() / 1024 + " kilobytes ");
    System.out.println(file.getTotalSpace()/ 1024 + " kilobytes ");
    System.out.println(file.getUsableSpace()/1024+ " kilobytes ");
  }
}

Output:

183695348 kilobytes 
233167868 kilobytes 
183695348 kilobytes

 

NOUR-IT

IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*