[英]Why does this throw java.nio.file.InvalidPathException?
程序拋出
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
當我嘗試獲取文件的路徑時
Path path = Paths.get("E:\\New folder");
這是為什么? 獲取路徑時是否允許驅動器號?
„:“ 是„at index 2“,即字符串的第三個字符。 驅動器號應該在索引 0 處,“:”應該在索引 1 處。
您的字符串中有一個零寬度字符。 您可以通過使用箭頭鍵一個字母一個字母地移動光標來找到該字符。 字符是光標似乎對按鍵沒有反應的地方。
當我從 Windows 的“文件屬性”對話框、安全頁面、“對象名稱”復制文件路徑時,我看到這種情況發生,當我用鼠標從頭到尾選擇路徑時,有一個非打印的 unicode“left-驅動器號前的“向右嵌入”字符 (U+202A)。 即使啟用了¶它也不可見(我嘗試過 Notepad++ 和 Eclipse)。 當我從頭到尾選擇路徑時,這不會發生。
感謝 Slaw ,他在評論中指出了正確的方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.