The code below prints all the directories and files under supplied directory name. It further provides a filter class.
private static void doFileFilterListing(String dirName, String ff) {
System.out.println("Filter file listing...");
System.out.println("----------------------");
final String fileFilter = ff;
File dir = new File(dirName);
FilenameFilter filter = null;
if (fileFilter != null) {
// It is also possible to filter the list of returned files.
// This example uses the passed in String value (if any) to only
// list those files that start with the given String.
filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.startsWith(fileFilter);
}
};
}
String[] children = dir.list(filter);
printFiles(children, dirName);
}