接口回调;new FileFilter(接口)重写accept递归深度遍历后缀名文件;File[]和stringbuffer两种方法

来源:互联网 发布:雪利酒 知乎 编辑:程序博客网 时间:2024/06/05 23:05
import java.io.File;




public class dadaIO {
static StringBuffer res = new StringBuffer();

private static void fun(File file) {
File[] files=file.listFiles(new java.io.FileFilter() {
@Override
public boolean accept(File pathname) {
if(pathname.isDirectory())
fun(pathname);
// else if(pathname.toString().endsWith(".txt"))
// res.append(pathname+"\n");
return pathname.toString().endsWith(".txt");//return false;
}
});
for (File f  : files) {
System.out.println(f);  
}
}


public static void main(String[] args) {
File file = new File("E:\\myeclipse2014");
fun(file);
// System.out.println(res);


}
}
1 0
原创粉丝点击