How to filter files in java?

If you want to list out all files from a given directory or drive you can use the list method in the java.io.File class. Consider a scenario where you wanted to list out all files with specific extension. FileFilter interface will help you to filter files using any criteria you can imagine. Today we will look at the use of FileFilter interface with a simple example. Given below example will recursively list out all java files in the given location and given extension.

Console Output.

One thought on “How to filter files in java?