我使用递归函数扫描/mnt/sdcard下的所有路径并找出所有以.txt结尾的文件,但我发现如果我在真正的android手机上使用它会很慢。有没有像缓冲输入流这样的东西来加快扫描过程?
private txtFileFilter txtff = new txtFileFilter();
private void scanAllTxtFiles(File location, ArrayList<String> list) {
File[] files = location.listFiles(txtff);
if (files != null) {
for (File f : files) {
if (f.isDirectory()) {
scanAllTxtFiles(f, list);
} else if (f.isFile()) {
list.add(f.getAbsolutePath().substring(
externalPathLength));
}
}
}
}
}
private class txtFileFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
// TODO Auto-generated method stub
if (pathname.isFile()
&& pathname.getName().length() >= 4
&& pathname.getName()
.substring(pathname.getName().length() - 4)
.equals(".txt")) {
return true;
} else if (pathname.isDirectory()) {
return true;
}
return false;
}
}