如何在Java文件路径中使用通配符 [英] How to use a Wildcard in Java filepath
本文介绍了如何在Java文件路径中使用通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否以及如何在Path定义中使用通配符. 我想更深入地使用一个文件夹并尝试使用*,但这不起作用.
i want to know if and how i could use a Wildcard in a Path definition. I want to go one folder deeper and tried using the * but that doesnt work.
我想访问随机文件夹中的文件.文件夹结构是这样的:
I want to get to files that are in random folders. Folderstructure is like this:
\test\orig\test_1\randomfoldername\test.zip
\test\orig\test_2\randomfoldername\test.zip
\test\orig\test_3\randomfoldername\test.zip
我尝试过的事情:
File input = new File(origin + folderNames.get(i) + "/*/test.zip");
File input = new File(origin + folderNames.get(i) + "/.../test.zip");
提前谢谢!
推荐答案
我认为不可能以这种方式使用通配符.我建议您对任务使用类似的方法:
I don't think that it's possible to use wildcard in such way. I propose you to use a way like this for your task:
File orig = new File("\test\orig");
File[] directories = orig.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
ArrayList<File> files = new ArrayList<File>();
for (File directory : directories) {
File file = new File(directory, "test.zip");
if (file.exists())
files.add(file);
}
System.out.println(files.toString());
这篇关于如何在Java文件路径中使用通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文