Mittwoch, 17. Juni 2009 - a pragmatic and powerful way to select files

Today I discovered the FileFilter interface. A little bit late maybe - but better late than never!
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.

Keine Kommentare:

  © Blogger template 'Morning Drink' by 2008

Back to TOP