为什么PathMatcher与路径不匹配? [英] Why does PathMatcher doesn't match path?

查看:561
本文介绍了为什么PathMatcher与路径不匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我研究了glob模式.

I research glob patterns.

我写了一个简单的例子:

I wrote simple example:

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

此代码返回false.

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

If I use one star in pattern - I see same result.

我怎么了?

推荐答案

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

Try with \\\\ in path expression, to escape directory and reg expression

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

这篇关于为什么PathMatcher与路径不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆