开发者

A FileSet package/class wanted for Java

Can anyone suggest a FileSet pa开发者_运维百科ckage/class in Java. By FileSet I mean a collection of files and directories together with regex-powered inclusion and exclusion rules (similar to Apache Ant). Thanks.


Apache Commons IO FileUtils may be what you want. It has the capability to identify files with an optional filename filter that you can implement yourself.

See the doc for listFiles() or iterateFiles() for more info.


You could make use of File#listFiles() wherein you pass a FileFilter or FilenameFilter where in turn you can specify the desired pattern in the accept() method.

E.g.

File[] txtFiles = file.listFiles(new FilenameFilter() {
    @Override public boolean accept(File dir, String name) {
        return name.endsWith(".txt"); // You can use String#matches() as well.
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜