Here you can find the source of getAllFilesByProfix(String path, String suffix, List
public static void getAllFilesByProfix(String path, String suffix, List<File> files)
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.List; public class Main { public static void getAllFilesByProfix(String path, String suffix, List<File> files) { File file = new File(path); if (file.isDirectory()) { File[] fs = file.listFiles(); if (fs != null) { for (File file2 : fs) { if (file2.isDirectory()) { getAllFilesByProfix(file2.getPath(), suffix, files); } else { if (suffix != null) { if (file2.toString().endsWith(suffix)) { files.add(file2); }//from w w w . j a v a 2 s . co m } else { files.add(file2); } } } } } else { if (suffix != null) { if (file.toString().endsWith(suffix)) { files.add(file); } } else { files.add(file); } } } }