Home > DeveloperSection > Forums > How do I check if a file exists in Java?
Mikki Halpin
Mikki Halpin

Total Post:23

Posted on    August-02-2015 11:29 PM

 Java Java  File 

 1 Reply(s)
 689  View(s)
Rate this:
How can I check whether a file exists, before opening it for reading in Java? (equivalent of Perl's -e $filename).

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    August-03-2015 1:10 AM

Use java.io :
File f = new File(filePathString);
if(f.exists() && !f.isDirectory()) { /* do something */ }

Don't want to miss updates? Please click the below button!

Follow MindStick