使用FilenameFilter过滤出文件
代码示例:
String path = "/sdcard";
File dir = new File(path);
File[] files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !new File(dir, name).isDirectory();
}
});
if (files != null) {
for (File file : files) {
// 处理文件
}
}