Determine File or Directory - Java File Path IO

Java examples for File Path IO:Directory

Description

Determine File or Directory

Demo Code

  
import java.io.File;

public class Main {
  public static void main(String[] args) {
    File file = new File("C://FileIO");

    boolean isFile = file.isFile();
    if (isFile)/*  w  ww .j  a  va 2  s  .  co m*/
      System.out.println(file.getPath() + " is a file.");
    else
      System.out.println(file.getPath() + " is not a file.");

    boolean isDirectory = file.isDirectory();
    if (isDirectory)
      System.out.println(file.getPath() + " is a directory.");
    else
      System.out.println(file.getPath() + " is not a directory.");
  }
} 
  

Related Tutorials