Java 中的文件迭代器?
你知道我在哪里可以找到一个在 Java 中实现 FileIterator (或类似的东西)的库吗?让它像下面这样工作(未经检查的代码)会很好:
Iterator it = new FileIterator();
it.addDirectory("../some-dir/");
it.addInclude("**/*.java");
it.addExclude(".svn/**");
while (it.hasNext()) {
File f = it.next();
System.out.println("File found: " + f);
}
Maven FileSet,但我不认为将 Maven JAR 添加到我的项目中是个好主意:)
Do you know where I can find a library that implements FileIterator (or something similar) in Java? Would be nice to have it working like the following (unchecked code):
Iterator it = new FileIterator();
it.addDirectory("../some-dir/");
it.addInclude("**/*.java");
it.addExclude(".svn/**");
while (it.hasNext()) {
File f = it.next();
System.out.println("File found: " + f);
}
Something similar is implemented in Maven FileSet, but I don't think it's a good idea to add Maven JAR to my project :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看
org.apache。 commons.io.FileUtils.iterateFiles(..)
Have a look at
org.apache.commons.io.FileUtils.iterateFiles(..)
您可以在 Commons-IO 中使用 DirectoryWalker,以下是示例:
其他示例可以在 http://commons.apache.org/io/api-2.0/index.html?org/apache/commons/io/FileUtils.html
You can use DirectoryWalker in Commons-IO, here is example:
Other examples can be found at http://commons.apache.org/io/api-2.0/index.html?org/apache/commons/io/FileUtils.html