如果我想在Java中创建Path
实例,我应该写出类似以下的代码:
Paths.get("D:\\dir1\\dir2\\dir3");
因此我应该使用双反斜杠
同时我也可以使用单斜杠
Paths.get("D:/dir1/dir2/dir3");
如果我想写GLOB模式,有以下几种变体:
FileSystems.getDefault().getPathMatcher("glob:D:/dir1/dir2/**");
或者
FileSystems.getDefault().getPathMatcher("glob:D:\\\\dir1\\\\dir2\\\\**");
我不理解这个转义魔法,请您解释一下。
getPathMatcher("glob:D:\\dir1\\dir2\\**");
是无效的,否则这个答案并不特别有帮助。 - undefined