文件过滤 看 java 回调
?
运行,输出结果为
类型的文件: a.txt
类型的文件: b.txt?
查看源码:
?
/** * Returns an array of strings naming the files and directories in the * directory denoted by this abstract pathname that satisfy the specified * filter. The behavior of this method is the same as that of the * <code>{@link #list()}</code> method, except that the strings in the * returned array must satisfy the filter. If the given * <code>filter</code> is <code>null</code> then all names are accepted. * Otherwise, a name satisfies the filter if and only if the value * <code>true</code> results when the <code>{@link * FilenameFilter#accept}</code> method of the filter is invoked on this * abstract pathname and the name of a file or directory in the directory * that it denotes. * * @param filter A filename filter * * @return An array of strings naming the files and directories in the * directory denoted by this abstract pathname that were accepted * by the given <code>filter</code>. The array will be empty if * the directory is empty or if no names were accepted by the * filter. Returns <code>null</code> if this abstract pathname * does not denote a directory, or if an I/O error occurs. * * @throws SecurityException * If a security manager exists and its <code>{@link * java.lang.SecurityManager#checkRead(java.lang.String)}</code> * method denies read access to the directory */ public String[] list(FilenameFilter filter) {String names[] = list();if ((names == null) || (filter == null)) { return names;}ArrayList v = new ArrayList();for (int i = 0 ; i < names.length ; i++) { if (filter.accept(this, names[i])) {v.add(names[i]); }}return (String[])(v.toArray(new String[0])); }?
很优雅.......
?
使用内部类 更优雅
?
http://www.blogjava.net/hwpok/archive/2008/04/01/190196.html
http://blog.sina.com.cn/s/blog_48cf38890100go6x.html
?
?