Java File.isFile()

Syntax

File.isFile() has the following syntax.

public boolean isFile()

Example

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


/*ww  w  . j a  v a2 s  .c o  m*/

import java.io.File;

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

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

    // true if the file path is a file, else false
    boolean bool = f.isFile();

    // get the path
    String path = f.getPath();

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

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

    // true if the file path is a file, else false
    bool = f.isFile();

    // get the path
    path = f.getPath();

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

  }
}

The code above generates the following result.