Java – Check File and Directory Existence

You can Check the file/directory existence as follow.

File f = new File("<file/directory path>");
if (!f.exists()) {
  // The directory does not exist.
} else if (!f.isDirectory()) {
  // It is not a directory (i.e. it is a file).
}

 

The Java File IO also provides f.isFile() for checking file.

Done =)

Reference: StackOverflow – How to Check Path is existing or not in java?

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.