[ACCEPTED]-How to Check Path is existing or not in java?-file-io
Accepted answer
if (!new File("D:\\Log\\Sample").exists())
{
throw new FileNotFoundException("Yikes!");
}
Besides File.exists()
, there are also File.isDirectory()
and File.isFile()
.
0
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).
...
}
new File( path ).exists().
Read the javadoc 2 its very useful and often gives many useful 1 examples.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.