Java IO Tutorial - Java File.getFreeSpace()








Syntax

File.getFreeSpace() has the following syntax.

public long getFreeSpace()

Example

In the following code shows how to use File.getFreeSpace() method.

/*www. j a  va  2s .c om*/

import java.io.File;

public class Main {
  public static void main(String[] args) throws Exception {

    // create new files
    File f = new File("c:/");

    long size = f.getFreeSpace();

    System.out.print(size);

  }
}

The code above generates the following result.