Here you can find the source of getFilesFiteredByExtension(final File parent, final List
public static List<File> getFilesFiteredByExtension(final File parent, final List<String> extensions)
//package com.java2s; /**/*from w w w .java2 s. c o m*/ * * Licensed under the GNU General Public License (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.gnu.org/licenses/gpl.txt * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * * @author Vadim Kisen * * copyright 2010 by uTest */ import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { public static List<File> getFilesFiteredByExtension(final File parent, final List<String> extensions) { final List<File> res = new ArrayList<File>(); if (!parent.isDirectory()) { return res; } for (final File file : parent.listFiles()) { if (matchByExtension(file, extensions)) { res.add(file); } } return res; } private static boolean matchByExtension(final File file, final List<String> exts) { if (file.isDirectory()) { return false; } final String ext = file.getName().substring(file.getName().lastIndexOf(".") + 1); for (final String extension : exts) { if (extension.equalsIgnoreCase(ext)) { return true; } } return false; } }