package cn.stat.p1.file; import java.io.File; public class newfilelist { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub File f1=new File("C:\"); String[] name=f1.list(new filefilter(".txt")); for(String n : name) { System.out.println(n); } } }
package cn.stat.p1.file; import java.io.File; import java.io.FilenameFilter; public class filefilter implements FilenameFilter { private String sux; @Override public boolean accept(File dir, String name) { // TODO Auto-generated method stub return name.endsWith(sux); } public filefilter(String sux) { super(); this.sux = sux; } }