让我们:
Path path = Paths.get("C:\\1.txt");
以下代码打印“true”:
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("regex:.*");
System.out.println(matcher.matches(path));
但以下代码打印“false”:
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*");
System.out.println(matcher.matches(path));
为什么?
我期望这两种方法都具有true
。
根据Glob page from Wikipedia ,通配符*
的意思是:
matches any number of any characters including none
详细信息:
- Java 8
- Windows 7
最佳答案
正如 @T.J Crowder 所说,你应该很好地接受这个:
PathMatcher matcher2 = FileSystems.getDefault().getPathMatcher("glob:**");
System.out.println(matcher2.matches(path));
有关更多信息,请参阅 this其中说:
The ** characters matches zero or more characters crossing directory boundaries.
关于java - 为什么没有 glob :* match any path in PathMatcher?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37724969/