Pass the FileFilter
(encoded here anonymously ) to listFiles()
the File
method, for example:
File dir = new File("some/path/to/dir"); final String id = "XXX";
As a method, it will look like this:
public static File[] findFilesForId(File dir, final String id) { return dir.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().equals("a_id_" + id + ".zip"); } }); }
and which you can name as follows:
File[] matchingFiles = findFilesForId(new File("some/path/to/dir"), "XXX");
or just check availability,
boolean exists = findFilesForId(new File("some/path/to/dir"), "XXX").length > 0
Bohemian
source share