How to determine if a File or Directory exists in Java


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
}

 

 

About author


User avatar

Waqas Anwar

Founder of EzzyLearning.com, Senior Consultant, Microsoft .NET and Web Technologies

Comments