- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在阅读 OCA/OCP Java SE & Programmer I & II 学习指南。在第 520 页上有一种用于匹配的方法:
public void matches(Path path, String glob){
PathMatcher matcher = FileSystems.getDefault().getPathMatcher(glob);
System.out.println(matcher.matches(path));
}
现在,在下一页中有一段使用此方法的代码:
public static void main(String [] args){
Path path1= Paths.get("0*b/test/1");
Path path2 = Paths.get("9\\*b/test/1");
Path path3 = Paths.get("01b/test/1");
Path path4 = Paths.get("0*b/1");
String glob = "glob:[0-9]\\*{A*,b}/**/1";
matches(path1,glob);
matches(path2,glob);
matches(path3,glob);
matches(path4,glob);
}
根据书上的结果应该是:真的错误的错误的假的
但是,当我尝试运行它时,出现以下异常:
Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <*> at index 1: 0*b/test/1
at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
at java.nio.file.Paths.get(Paths.java:84)
at pathmatcherobjective.PathMatcherObjective.main(PathMatcherObjective.java:63)
Java Result: 1
我的问题是:我是否遗漏了设置中的某些内容?我需要启用某些特定功能才能运行它吗?还是这本书错了?我只是在为 Java Professional 考试而学习,所以我不确定所有事情。
最佳答案
在 Windows 操作系统上,字符 *
不允许用于有效的文件和目录名称。 Microsoft Developer Network 上列出的字符也是如此:
You can use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following reserved characters:
- < (less than)
- > (greater than)
- : (colon)
- " (double quote)
- / (forward slash)
- \ (backslash)
- | (vertical bar or pipe)
- ? (question mark)
- * (asterisk)
- Integer value zero, sometimes referred to as the ASCII NUL character.
- Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. For more information about file streams, see File Streams.
- Any other character that the target file system does not allow.
对于 UNIX,请参阅 Wikipedia .在 POSIX 上,允许的字符包括 A–Z a–z 0–9 。 _ -
,保留为/null
。
可能是在允许 *
的操作系统上运行的示例。
关于java - Java 路径中的星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27522581/
*args 和 **kwargs 是什么意思? def foo(x, y, *args): def bar(x, y, **kwargs): 最佳答案 *args 和 **kwargs 是一个常见的惯
*args 和 **kwargs 是什么意思? def foo(x, y, *args): def bar(x, y, **kwargs): 最佳答案 *args 和 **kwargs 是一个常见的惯
*args 和 **kwargs 是什么意思? def foo(x, y, *args):def bar(x, y, **kwargs): 最佳答案
在python文档中2.4.3. Formatted string literals ,似乎可以在 f 字符串的 {} 中写一个星号后跟一个表达式,但我找不到如何使用它。 那是什么以及如何使用它?它是
这些函数定义中的*args和**kwargs是什么意思? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass 参见Wha
这些函数定义中的*args和**kwargs是什么意思? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass 参见Wha
这个问题在这里已经有了答案: Delegated yield (yield star, yield *) in generator functions (3 个答案) 关闭 6 年前。 假设我创建了
我有时注意到使用 *偶尔搜索光标下的单词会有略微不同的行为(通常是当我在不同的计算机之间切换时)。问题是当我搜索前面有 * 的单词时(如 c++ 指针)。例如: MyPointer *foo; ...
This question already has answers here: Keyword only parameter (1个答案) Python documentation for os.re
这是我的数据: dput(dt) structure(c(15236000, 0, 0, 0, 0, 36722900, 45971100, 0, 0, 0, 0, 99067
所以我有一个看起来像这样但有 6k 行的数据框: AWC, LocationID 333, *Yukon 485, *Lewis Rich 76, *Kodiak 666, Kodiak 54, *R
我有一个简单的问题。我想列出我们可以使用关键字星号(或星号)* 的所有场景。 我只知道这些场景: Select * from Customers; Select Count(*) from Custo
瑞安·贝茨的Railscast about git ,他的 .gitignore 文件包含以下行: tmp/**/* 使用双星号后跟一个星号的目的是什么:**/*?简单地使用 tmp/* 而不是 tm
我想以这种方式选择带有 class="x"的元素的所有后代元素: .x * { color: red; } a b
这个问题在这里已经有了答案: What does ** (double star/asterisk) and * (star/asterisk) do for parameters? (25 个答案
最近我在 Programming Paradigms 上看到了这个视频和教授。使用星号、星形和符号等术语。 这就是他如何使用这些运算符的: int i = 37; float f = *(float*
我尝试在自定义按钮中居中对齐符号星号 (*),但我做不到。 如何像其他字符一样垂直居中对齐(1,2...)? 最佳答案 只需使用不同的字符。除了 * (ASTERISK U+002A),还有许多其他类
结论 概括的来说,就是对修饰的变量进行拆分, 对修饰的形式参数进行参数聚集。 单*号,将被修饰的变量按元素方式拆分, 对修饰的形式参数进行参数聚集。 双**号,将被修饰的变量按键值对进行拆分, 对
如果我想保持功能,并且不想在中间使用 *,那么等效的替代函数是什么?例如, import operator as op print(op.eq(*map(str.upper, ['a', 'A']))
我窥视 ng2-dropdown 我可以看到(ng2-dropdown-menu.ts) 除其他事项外 transition('hidden => visible', [
我是一名优秀的程序员,十分优秀!