I am trying to get a piece of code working. The aim is to check if there is an .XML file in a certain directory.
This is what I've got so far.
File f = new File("saves/*.xml");
if(f.exists()) {
/* Do Something */
} else {
/* do something else */
}
I'm trying to use a wildcard to search for any file ending in .XML, am I missing something simple here? Is there an easier way to check that at least one .XML file exists in a specified directory?
thanks in advance.
f
isNULL
or not... tried ?? – Tumf
won't benull
, it's assigned tonew File("saves/*.xml");
just one line above. This doesn't mean the file exists, butf
won't benull
. – Zoanf
should be containingnull
... Am I wrong somewhere ..? – Tumf
references aFile
object, notnull
. Whether the file denoted by the abstract path name stored in that object exists is a whole other question. Just run following code:File f = new File("DOESNOTEXIST"); if (f != null) {System.out.println("f is not null");}
– Zoan