How can I check whether a file exists, before opening it for reading in Java (the equivalent of Perl\'s -e $filename>
-e $filename>
Don't use File constructor with String. This may not work! Instead of this use URI:
File f = new File(new URI("file:///"+filePathString.replace('\\', '/'))); if(f.exists() && !f.isDirectory()) { // to do }