How to determine if a File or Directory exists in Java

Waqas Anwar
25 June 2009
2854 Views

If you want to know about a particular File or Directory physically exists in File System you can use exists method of File class

File file = new File("D:\\Java\\Example.java");

if(file.exists())
{
   // File or Directory exist
}
else
{
   // File or Directory does not exist
}