方便指定文件类型过滤器
public static void main(String[] args) throws IOException { method_7(); } public static void method_7() { File file=new File("c:\\"); File[] names=file.listFiles(new SuffixFilter(".java"));//得到文件目录 for(File name:names) { sop(name); } }
实现的接口
package Demo1; import java.io.File; import java.io.FilenameFilter; public class SuffixFilter implements FilenameFilter { private String suffix; public SuffixFilter(String suffix) { super(); this.suffix=suffix; } @Override public boolean accept(File dir, String name) { // TODO Auto-generated method stub return name.endsWith(suffix); } }
可以查出隐藏文件的接口
public class FileByhidden implements FileFilter { @Override public boolean accept(File pathname) { return pathname.isHidden(); } }