February 2014
Intermediate to advanced
160 pages
4h 59m
English
Java has long provided a variation of the list method to cherry-pick filenames. This version of list takes a FilenameFilter as its parameter. This interface has one method, accept, that takes two parameters: File dir (representing the directory) and String name (representing a filename). We’d return a true from the accept method to include the given filename in the list, and false otherwise. Let’s explore the options to implement this method.
It’s a habitual practice in Java to pass to the list method an instance of an anonymous inner class that implements the FilenameFilter interface. For example, let’s look at how we’d select only the java files in a fpij directory using that approach.
| compare/fpij/ListSelectFiles.java ... |
Read now
Unlock full access