Determine if file or directory exists
- /*
- Determine if file or directory exists
- This Java example shows how to determine if a particular file or directory
- exists in the filesystem using exists method of Java File class.
- */
- import java.io.*;
- public class DetermineIfFileExists {
- public static void main(String[] args) {
- //create file object
- File file = new File("C://FileIO/ExistsDemo.txt");
- /*
- * To determine whether specified file or directory exists, use
- * boolean exists() method of Java File class.
- *
- * This method returns true if a particular file or directory exists
- * at specified path in the filesystem, false otherwise.
- */
- boolean blnExists = file.exists();
- System.out.println("Does file " + file.getPath() + " exist ?: " + blnExists);
- }
- }
- /*
- Output would be
- Does file C:\FileIO\ExistsDemo.txt exist ?: true
- */



