栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

何时在JAVA的glob语法中使用**(双星)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

何时在JAVA的glob语法中使用**(双星)

的Javadoc

FileSystem#getPathMatcher()
有一些非常好的示例和解释

*.java Matches a path that represents a file name ending in .java *.*    Matches file names containing a dot*.{java,class}  Matches file names ending with .java or .class foo.?Matches file names starting with foo. and a single character extension /home/*/*       Matches /home/gus/data on UNIX platforms /home/**        Matches /home/gus and /home/gus/data on UNIX platforms C:\*Matches C:foo and C:bar on the Windows platform (note that the backslash is escaped; as a string literal in the Java Language the pattern would be "C:\\*")

因此

/home/**
将匹配
/home/gus/data
,但
/home/*
不会。

/home/*
直接说
/home
目录中的每个文件。

/home/**
说里面的任何目录的每个文件
/home


的例子

*
VS
**
。假设您当前的工作目录为
/Users/username/workspace/myproject
,则以下内容仅与
./myproject
文件(目录)匹配。

PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:/Users/username/workspace/*");Files.walk(Paths.get(".")).forEach((path) -> {    path = path.toAbsolutePath().normalize();    System.out.print("Path: " + path + " ");    if (pathMatcher.matches(path)) {        System.out.print("matched");    }    System.out.println();});

如果使用

**
,它将匹配该目录中的所有文件夹和文件。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/497501.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号