[ACCEPTED]-How to Check Path is existing or not in java?-file-io

Accepted answer
Score: 28
if (!new File("D:\\Log\\Sample").exists())
   throw new FileNotFoundException("Yikes!");

Besides File.exists(), there are also File.isDirectory() and File.isFile().


Score: 12

The class java.io.File can take care of 1 that for you:

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

new File( path ).exists().

Read the javadoc 2 its very useful and often gives many useful 1 examples.

More Related questions