Jakarta Commons IO

I have written plenty of one-off no-brainer recursive Java methods that search through a directory hierarchy searching for a type of files. Such methods are good exercise problems for rookie Java programmers. But since I am a Java programmer I bearly exercise, so I tend not to write that type of method anymore. I let Jakarta Commons IO do the recusive file seach for me. Using the FileUtils, SuffixFileFilter, and TrueFileFilter from the Commons IO library I could recursively search a directory hierarchy for all groovy files with the following bit of code:

SuffixFileFilter sff = new SuffixFileFilter(".groovy");
// listFiles(File directory, IOFileFilter fileFilter, IOFileFilter  dirFilter)
Collection cl = FileUtils.listFiles(f, sff, TrueFileFilter.INSTANCE);

Other useful FileFilter classes available in the Commons IO library include PrefixFileFilter, NamedFileFilter, DirectoryFileFilter, and FalseFilterFilter.

Technorati Tags: , , , ,

Related posts:

  1. Jakarta Commons Lang Builders
  2. Jakarta BeanUtils PropertyUtils Nested Properties
  3. Embedding Groovy
  4. Jakarta BeanUtils PropertyUtils
  5. Software Project Management with Maven 2

This entry was posted in Java, TechKnow. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*