Why does PathMatcher doesn't match path?

岁酱吖の 提交于 2019-12-12 04:08:58

问题


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);

This code returns false.

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

What do I wrong?


回答1:


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);


来源:https://stackoverflow.com/questions/25259869/why-does-pathmatcher-doesnt-match-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!