SingleFilenameFilter myFilenameFilter = new SingleFilenameFilter()
List myList = new File("/tmp").listFiles(myFilenameFilter)
Why should I have to create a class that implements FilenameFilter, just to filter on some file names? Especially in a one-off instance, why should I have to create a class that I will only ever use once?
Why isn't there a default implementation? Something like:
public class RegexFilenameFilter implements FilenameFilter {
private String regex;
public RegexFilenameFilter(String re) {
this.regex = re;
}
public accept(File dir, String name) {
// matching here
}
}
Then I could just write:
List relevantFiles = new File("/tmp").listFiles(new RegexFilenameFilter("^tmp\\.[a-z0-9]+$"))
Why should I have to create this class for every project (or create my own little 'utils' library)? It's easily one of the simplest usages of a FilenameFilter.
Why isn't there a default implementation? Something like:
Then I could just write: Why should I have to create this class for every project (or create my own little 'utils' library)? It's easily one of the simplest usages of a FilenameFilter.