import java.io.FilenameFilter;
import java.io.File;
class HTMLFilter implements FilenameFilter {
public boolean accept(File dir, String name) {
return (name.endsWith(".html"));
}
}
class Main {
public static void main(String[] args) {
String dir = ".";
if (args.length == 1) {
dir = args[0];
}
File f1 = new File(dir);
int i;
String[] ls;
FilenameFilter filter = new HTMLFilter();
System.out.println("HTML Files: ");
for (ls = f1.list(filter), i = 0;
ls != null && i < ls.length;
System.out.println("\t" + ls[i++])) {
;
}
}
}
[REF]http://home.tiscali.nl/~bmc88/java/sbook/0128.html
沒有留言:
張貼留言