File[] libs = libDir.listFiles(new FileFilter() { public boolean accept(File pathname) { return !pathname.isDirectory() && pathname.getName().endsWith(".jar"); } });This example is a very simple one but since this is a method instead of a pattern like *.jar there are no limitations how the filtering is done. Regular expressions, web services, databases, relations of file names, ... I do like that approach since even it is powerful it's still simple and easy to use. If all API's were designed like this software development would be simpler and faster.
test driving of java applications
Mittwoch, 17. Juni 2009
java.io.FileFilter - a pragmatic and powerful way to select files
Today I discovered the FileFilter interface. A little bit late maybe - but better late than never!
Abonnieren
Kommentare zum Post (Atom)
Keine Kommentare:
Kommentar veröffentlichen