Java File check file existence

Description

Java File check file existence

import java.io.File;

public class Main {
  public static void main(String[] args) throws Exception {
    // Create a File object
    File myFile = new File("Main.java");

    // Check for the file's existence
    boolean fileExists = myFile.exists();
    if (fileExists) {
      System.out.println("exists.");
    } else {/*w w  w  .  j  a  va  2 s .co m*/
      System.out.println("not exist.");
    }

  }
}



PreviousNext

Related