I made a simple script that do what you needed! :)
It search in the given directory all the files, and if the given extension is equals to the file extension, it save the file name to a list that is returned later.
import java.io.*;
import java.util.*;
public class FileFinder{
public static List<File> findFile(File file, String extension){
File[] fileList = file.listFiles();
List<File> returnList = new ArrayList<File>();
if(fileList!=null){
for(File fil : fileList){
if(fil.isDirectory()){ findFile(fil, extension); }
else if(fil.getName().endsWith(extension)) {
System.out.println(fil.getName());
returnList.add(fil);
}
}
}
return returnList;
}
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the extension to be searched: ");
String extension = scan.next();
System.out.println("Enter the directory where to search: ");
String directory = scan.next();
List<File> fileList = findFile(new File(directory), extension);
//System.out.println(fileList);
}
}
P.S. this is an arrangment of this answer: Java - Search for files in a directory