Here you can find the source of getFileList(File folder, String type)
Parameter | Description |
---|---|
folder | the folder you want to check |
type | the file type you want to filter |
public static List<File> getFileList(File folder, String type)
//package com.java2s; import java.io.File; import java.util.ArrayList; import java.util.List; public class Main { public static final String FILE_TYPE_FOLDER = "dir"; /**/*from w w w . j a v a2 s . co m*/ * * @param folder * the folder you want to check * @param type * the file type you want to filter * @return */ public static List<File> getFileList(File folder, String type) { List<File> fileNameList = new ArrayList<File>(); File[] files = folder.listFiles(); for (File file : files) { if (getFileType(file).equalsIgnoreCase(type)) { fileNameList.add(file); } } return fileNameList; } /** * * @param file * @return the file type like "exe" */ public static String getFileType(File file) { if (file.isDirectory()) { return FILE_TYPE_FOLDER; } else { String[] strArray = file.getName().split("\\."); int length = strArray.length; if (length > 1) { return strArray[length - 1]; } else { return "unknown"; } } } }