简体   繁体   English

为什么这会抛出 java.nio.file.InvalidPathException?

[英]Why does this throw java.nio.file.InvalidPathException?

The program throws程序抛出

 Exception in thread "main" java.nio.file.InvalidPathException: Illegal char 
  <:> at index 2: ‪E:\New folder
      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 
 javaapplication10.ACDirectoryListenerServiceImpl.main(ACDirectoryListenerServiceImpl.java:93)
Java Result: 1

When I try to get a path of a file with当我尝试获取文件的路径时

Path path = Paths.get("‪E:\\New folder");

why is that?这是为什么? Are drive letters allowed when getting paths?获取路径时是否允许驱动器号?

The „:“ is „at index 2“, that is the third character of the string. „:“ 是„at index 2“,即字符串的第三个字符。 The drive letter should be at index 0, and the „:“ should be at index 1.驱动器号应该在索引 0 处,“:”应该在索引 1 处。

There is a zero-width character in your string.您的字符串中有一个零宽度字符。 You can find the character by moving the cursor letter by letter with the arrow keys.您可以通过使用箭头键一个字母一个字母地移动光标来找到该字符。 The character is where the cursor seems not to react to the keypress.字符是光标似乎对按键没有反应的地方。

I see this happening when I copy a file path from Windows' “file properties” dialog, security page, „object name“, when I select the path with the mouse from end to beginning , there is a non-printing unicode “left-to-right embedding” character (U+202A) before the drive letter.当我从 Windows 的“文件属性”对话框、安全页面、“对象名称”复制文件路径时,我看到这种情况发生,当我用鼠标从头到尾选择路径时,有一个非打印的 unicode“left-驱动器号前的“向右嵌入”字符 (U+202A)。 It is not visible even with enabled (I tried Notepad++ and Eclipse).即使启用了它也不可见(我尝试过 Notepad++ 和 Eclipse)。 This does not happen when I select the path from beginning to end.当我从头到尾选择路径时,这不会发生。

Credit to Slaw who pointed in the right direction in his comment.感谢 Slaw ,他在评论中指出了正确的方向。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.nio.file.InvalidPathException - java.nio.file.InvalidPathException 带有getPath的java.nio.file.InvalidPathException - java.nio.file.InvalidPathException with getPath 系统错误:java.nio.file.InvalidPathException: - SystemError: java.nio.file.InvalidPathException: 遇到java.nio.file.InvalidPathException:非法char &lt;:&gt; - Encountering java.nio.file.InvalidPathException: Illegal char <:> java.nio.file.InvalidPathException 当路径包含冒号 (:) - java.nio.file.InvalidPathException when the path contains colon (:) Magnolia 5.4在发布/取消发布时升级java.nio.file.InvalidPathException - Magnolia 5.4 upgrade java.nio.file.InvalidPathException on publishing/unpublishing 使用闭包编译器格式化javascript文件时,在索引7处获取到java.nio.file.InvalidPathException:非法char &lt;:&gt; - Got java.nio.file.InvalidPathException:Illegal char <:> at index 7 when formatting javascript file using closure compiler WFLYCTL0080 Spring MVC java.lang.RuntimeException:java.nio.file.InvalidPathException - WFLYCTL0080 Spring MVC java.lang.RuntimeException: java.nio.file.InvalidPathException 在尝试编译 java 文件时获取 java.nio.file.InvalidPathException: Illegal char &lt;*&gt; - Getting a java.nio.file.InvalidPathException: Illegal char <*> while trying to compile java files java.nio.file.InvalidPathException:使用国家字符时格式错误的输入或输入包含不可映射的字符 - java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters when using national characters
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM