Example & Tutorial understanding programming in easy ways.

How to Filter the files by file extensions and show the file names in java?.

In this example shows how to get specific files from a folder. Sometimes we need to pic only specific extensions from the given folder. Implement FilenameFilter class and override accept() method, and add your filter logic here. Pass this object to list() method to get specific file extensions.


package com.javatest.files;

import java.io.File;

import java.io.FilenameFilter;

public class FileFiltertest {

public static void main(String a[]){

File file = new File("C:/Myjava/");

String[] files = file.list(new FilenameFilter() {

public boolean accept(File dir, String name) {


return true;

} else {

return false;


for(String f:files){



Read More →
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!