How can I check whether a file exists, before opening it for reading in Java (the equivalent of Perl\'s
-e $filename>
Don't. Just catch the FileNotFoundException.
The file system has to test whether the file exists anyway. There is no point in doing all that twice, and several reasons not to, such as:
Don't try to second-guess the system. It knows. And don't try to predict the future. In general the best way to test whether any resource is available is just to try to use it.