Here you can find the source of getFileList(String dir, final String extension)
public static File[] getFileList(String dir, final String extension)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.ArrayList; public class Main { private static ArrayList<File> fileList; public static File[] getFileList(String dir, final String extension) { File folder = new File(dir); fileList = new ArrayList<File>(); traverse(folder, extension);//from w w w. j av a2 s. co m File[] fileArray = new File[fileList.size()]; fileList.toArray(fileArray); return fileArray; } public static final void traverse(final File f, String extension) { if (f.isDirectory()) { final File[] childs = f.listFiles(); for (File child : childs) { traverse(child, extension); } return; } // if file is extension add to list if (f.isFile() && f.getName().toLowerCase().endsWith(extension)) { fileList.add(f); } } }