Here you can find the source of findByExtension(final File directory, final String extension)
Parameter | Description |
---|---|
directory | the directory to search |
extension | the extension to search for |
public static List<File> findByExtension(final File directory, final String extension)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Main { /**// w w w. j a v a 2s . c o m * Find the files with an extension inside a directory. * * @param directory * the directory to search * @param extension * the extension to search for * @return the files inside the directory with the extension */ public static List<File> findByExtension(final File directory, final String extension) { assert directory.isDirectory(); File[] res = directory.listFiles(fileName -> fileName.getName().endsWith(extension)); if (res == null) { return Collections.emptyList(); } return Arrays.asList(res); } }