I want to find all files stored on sdCard. I used this code:
List dir = new ArrayList();
List files = new ArrayList
You can't add to a list while you're iterating over it. Try this instead:
List<File> dir = new ArrayList<File>();
List<File> files = new ArrayList<File>();
File root = new File (Environment.getExternalStorageDirectory().getAbsolutePath());
List<File> rootDirs = //... code to find root directories
for (File f : rootDirs) { // 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);
scan(f);
}
}
}