内容简介:如何根据id和File目录检查文件是否存在?翻译自:https://stackoverflow.com/questions/8752034/how-to-check-a-file-if-exists-with-wildcard-in-java
如何根据id和File目录检查文件是否存在?
将
FileFilter
(此处编码为 anonymously
)传递到dir
File
的
listFiles()
方法,如下所示:
File dir = new File("some/path/to/dir"); final String id = "XXX"; // needs to be final so the anonymous class can use it File[] matchingFiles = dir.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().equals("a_id_" + id + ".zip"); } });
捆绑为方法,它看起来像:
public static File[] findFilesForId(File dir, final String id) { return dir.listFiles(new FileFilter() { public boolean accept(File pathname) { return pathname.getName().equals("a_id_" + id + ".zip"); } }); }
你可以称之为:
File[] matchingFiles = findFilesForId(new File("some/path/to/dir"), "XXX");
或者只是检查是否存在,
boolean exists = findFilesForId(new File("some/path/to/dir"), "XXX").length > 0
翻译自:https://stackoverflow.com/questions/8752034/how-to-check-a-file-if-exists-with-wildcard-in-java
以上所述就是小编给大家介绍的《如何检查Java中是否存在带通配符的文件?》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- PowerShell转义通配符
- LeetCode44.通配符匹配 JavaScript
- Wildpwn:Unix通配符攻击工具
- Java 泛型之上界下界通配符
- 004-零失败快速搞定通配符SSL证书
- PHP源码调试之Windows文件通配符分析
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Shallows
Nicholas Carr / W. W. Norton & Company / 2010-6-15 / USD 26.95
"Is Google making us stupid?" When Nicholas Carr posed that question, in a celebrated Atlantic Monthly cover story, he tapped into a well of anxiety about how the Internet is changing us. He also crys......一起来看看 《The Shallows》 这本书的介绍吧!