I’m wondering if exist some way to check if a file exist without create an instance of java.io.File
Always I have used the following way:
File f = new File("./path/to/file");
if (f.exists()) {
doSomething();
}
else {
manageError();
}
But know I need check some filepaths in order to create elements like a logger (with log4j), xml editor and other project structures, but I don’t need work with them.
For this reason I want to know if this is possible.
I’m using J2SE-1.5_22.
Thanks in advance!
I don’t see what’s wrong with what you’re already doing. Creating an instance of
Fileisn’t going to create the file on disk or anything. You could always write a static method if you want:If that doesn’t satisfy your requirements, please explain what you’re trying to do that doesn’t work with this.