gpt4 book ai didi

java - 为什么 PathMatcher 不匹配路径?

转载 作者:行者123 更新时间:2023-12-01 12:39:25 26 4
gpt4 key购买 nike

我研究全局模式。

我写了一个简单的例子:

PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:D:\\folder1\\folder2\\**");
boolean isMatches = matcher.matches(Paths.get("D:\\folder1\\folder2\\folder3"));
System.out.println(isMatches);

此代码返回false

如果我在图案中使用一颗星 - 我会看到相同的结果。

我做错了什么?

最佳答案

尝试在路径表达式中使用\\\\,以转义目录和正则表达式

PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:D:\\\\dev\\\\server\\\\**");
boolean isMatches = matcher.matches(Paths.get("D:\\dev\\server\\web"));
System.out.println(isMatches);

关于java - 为什么 PathMatcher 不匹配路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25259869/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com