Apache FileUtils listFiles
Hey everyone I'm trying to get a List of directories. I'm using FileUtils listFiles().
I want to do something like this: listFiles(File,IOFileFilter,false). My real questions is how I can implement the accept() from the IOFileFilter so I can check if current File is a 开发者_如何学运维directory?
Thank you in advance.
File has an isDirectory()
method you can call, so:
final IOFileFilter dirs = new IOFileFilter() {
public boolean accept(File file) {
return file.isDirectory();
}
}
final IOFileFilter none = new IOFileFilter() {
public boolean accept(File file) {return false;}
};
listFiles(file, dirs, none);
I find Java 7+'s java.nio.file.SimpleFileVisitor described in The Java™ Tutorials, Walking the File Tree extremely helpful.
精彩评论