Java File.isDirectory()

Syntax

File.isDirectory() has the following syntax.

public boolean isDirectory()

Example

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


/*from  w  w  w .j a  v a  2  s  .co  m*/

import java.io.File;

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

    File f = new File("c:");

    boolean bool = f.isDirectory();

    String path = f.getPath();

    System.out.println(path + " is directory? " + bool);

    f = new File("c:/test.txt");

    bool = f.isDirectory();

    path = f.getPath();

    System.out.print(path + " is directory? " + bool);

  }
}

The code above generates the following result.