How to get all files with certain extension in a folder in java

In this post, we will see how to list all files with certain extension in a folder.
For example, you want to list all .jpg or .zip files in a folder.

We will  use FilenameFilter interface to list the files in a folder, so we will create a inner class which will implement FilenameFilter interface and implement accept method. We need to pass created inner class to java.io.File ‘s list method to list all files with specific extension.


Java Program :

When I ran above program, I got following output:

So we have found all .zip file in folder “/Users/Arpit/Desktop/Blog”

Add Comment