How do I check if a file exists in Java?

Total Post:23

Points:161
Java  File 
 1096  View(s)
Ratings:
Rate this:
How can I check whether a file exists, before opening it for reading in Java? (equivalent of Perl's -e $filename).
  1. Post:397

    Points:3117
    Re: How do I check if a file exists in Java?

    Use java.io :

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

Answer