开发者

Apache FileUtils listFiles

开发者 https://www.devze.com 2022-12-29 04:55 出处:网络
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 ishow I can implement th

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号