
I will Show you what I have.... LoL...
package folderList;
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
public class FolderList {
public void iterate(File folder) {
ArrayList<File> folders = getFolders(folder);
for (int i = 0; i < folders.size(); i++) {
System.out.println(folders.get(i));
// we add the subfolders of the current folder to the main FOLDERS array list
folders.addAll(getFolders(folders.get(i)));
// then we remove the current folder, so that we dont read it twice
folders.remove(i);
}
}
private ArrayList<File> getFolders(File folder) {
ArrayList<File> listAr = new ArrayList<File>();
// uses FileFilter to just pull out directories, then puts in an array
File[] list = folder.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
if (file.isDirectory())
return true;
return false;
}
});
// puts all the items from the array in an arraylist
for (int i = 0; i < list.length; i++)
listAr.add(list[i]);
return listAr;
}
public static void main(String[] args) {
FolderList myFolderList = new FolderList();
File File = new File("C:\\");
myFolderList.iterate(File);
}
}
Eclipse Error...
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method accept(File) of type new FileFilter(){} must override a superclass method
at folderList.FolderList.getFolders(FolderList.java:2 5)
at folderList.FolderList.iterate(FolderList.java:10)
at folderList.FolderList.main(FolderList.java:43)
Is it not working because something I am not doing....?
