开发者

A FileSet package/class wanted for Java

开发者 https://www.devze.com 2022-12-31 22:56 出处:网络
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

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

精彩评论

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