G.G我捉摩了下这个接口.也写了一个自已的应用来获取能匹配扩展名列表的文件集合.
大家pp.用匿名实现.
/** * Returns a list of files that the extension name matchs one of extensions. *Enjory it.Usage: getFilesByNameExtensions(dir, "txt", "JPEG");* @author GreatGhoul http://greatghoul.blogspot.com * @param dir The directory to scan in. * @param extensions Extensions collection. * @return A list of matched files. */ public static ListgetFilesByNameExtensions(File dir, final String... extensions) { return Arrays.asList(dir.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { File file = new File(dir, name); boolean accept = false; for (String extension : extensions) { if (file.isDirectory()) break; if (name.toLowerCase().endsWith("." + extension.toLowerCase())) { accept = true; break; } } return accept; } })); }
转载声明: 出自: Ghoul To World!作者: GreatGhoul
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.