JDK-6540610 : File{name}?Filter should have basic implementations
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 6
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-03-29
  • Updated: 2010-04-04
  • Resolved: 2009-02-16
Related Reports
Duplicate :  
Java should provide some basic implementations of the FileFilter and FilenameFilter interfaces: at least a 'filename extension' based and a 'regular expression' based.

Also, a 'bridge/adapter' class should be provided to easily allow FilenameFilter implementations, to easily implements FileFilter as well.


99% of the times a FileFilter/FilenameFilter is used, it is manually implemented each time around a set of extensions (like catching all .cfg .txt .whatever files) or around a regular expression.

Given that it's very very easy to provide a couple of implementations for these two cases, and given that a the strength of a language relies mostly on the strength and completeness of its libraries, I really think this is a 'hole' that can be easily filled up, and make customers (=developers) happy, instead of force them to write a custom implementation each time they even want to filter files by extension in a save dialog box.

I have myself coded at least for 5 different projects I've been working on, the same similar util classes ExtensionFileFilter and RegexFileFilter, they are LESS than 10 lines of code, and they allow me to avoid spamming sources with anonymous class each time I want to use a FileFilter.

I seriously think these should be in the java libraries :)

Java should give basic implementations (at least extension and regex) of FileFilter and FilenameFilter implementation, and also provide a way to easily 'wrap' FilenameFilter implementation as FileFilters.
_NO_ implementation of these interfaces is provided. Each time a developer want to do such a simple thing like filtering files by extension or by a regular expression, he has to provide an implementation for this interface.

If needed, I can easily provide a working version of ExtensionFileFilter and RegexFileFilter, alongs with a FilenameFileFilter which can acts both as a base class or a wrapper class, to make a FilenameFilter implements FileFilter interface.

EVALUATION This feature has been addressed by the new file system API defined by JSR-203. In particular, it supports built-in filtering using globs or regular expressions and a utility method to obtain a filter that filters by MIME type.