为什么PathMatcher与路径不匹配?

时间:2014-08-12 08:45:13

标签: java path match nio glob

我研究水珠模式。

我写了一个简单的例子:

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

此代码返回false

如果我在模式中使用一颗星 - 我看到相同的结果。

我错了什么?

1 个答案:

答案 0 :(得分:1)

尝试使用路径表达式中的\\\\来转义目录和reg表达式

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