Java:使用Apache commons-IO 2.4在子目录中递归列出文件 [英] Java: list files recursively in subdirectories with Apache commons-IO 2.4
本文介绍了Java:使用Apache commons-IO 2.4在子目录中递归列出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在根目录及其子目录中列出扩展名为.xls的文件,使用以下代码与 Apache Commons-IO 2.4
图书馆。我正在检查集合< File>
的大小,但是它给出了0.我没有看到代码中哪里出错。你可以帮帮我吗?
I'm trying to list files with the extension ".xls" in the root directory and its sub-directories, using the following code with Apache Commons-IO 2.4
library. I am checking the size of the collection<File>
, but it gives 0. I don't see where could be wrong in the code. Could you please help me with this?
public static void main(String[] args) throws IOException {
File rootDir = new File(args[0]);
Collection<File> files = FileUtils.listFiles(rootDir, new RegexFileFilter("[a-zA-Z].xls"), DirectoryFileFilter.DIRECTORY);
System.out.println("collection size:" + files.size());
}
推荐答案
我找到了这是有效的:
final String[] SUFFIX = {"xls"}; // use the suffix to filter
File rootDir = new File(args[0]);
Collection<File> files = FileUtils.listFiles(rootDir, SUFFIX, true);
这篇关于Java:使用Apache commons-IO 2.4在子目录中递归列出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文