To test to see if a file or directory exists, use the exists method of the Java File class, as shown in this example:
File tmpDir = new File("/var/tmp");
boolean exists = tmpDir.exists();
The existing method of the Java File class returns true if the file or directory exists, and false otherwise.
Hope this helps!
Join java online course to learn more.
Thanks!