I want to find all files stored on sdCard. I used this code:
List<File> dir = new ArrayList<File>();
List<File> files = new ArrayList<File>();
File root = new File (Environment.getExternalStorageDirectory().getAbsolutePath());
scan(root); // find root directories
for (File f : dir) { // find in root...
scan(f);
}
Log.i("files", "" + files.size());
Log.i("dir", "" + dir.size());
}
public void scan (File path) {
for (File f : path.listFiles()) {
if (f.isFile()) {
files.add(f);
}
else {
dir.add(f);
}
}
}
But I have problem with this exception: "java.util.ConcurrentModificationException" I change list (dir) and loop it. The ListIterator doesn't help.