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

Last updated on March 18th, 2017 at 10:38 am

Previous
Next
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”

Previous
Next

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.

Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog