问题
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