简体   繁体   English

java.nio.file.InvalidPathException 当路径包含冒号 (:)

[英]java.nio.file.InvalidPathException when the path contains colon (:)

I need to construct a path which contains colon (:).我需要构建一个包含冒号 (:) 的路径。 Actually the path is not a folder/directory in windows/linux.实际上,路径不是 windows/linux 中的文件夹/目录。 It is just a path of JCR repo.这只是 JCR repo 的一个路径。 Below code gives InvalidPathException when the path contains colon当路径包含冒号时,下面的代码给出 InvalidPathException

import java.nio.file.Path;
import java.nio.file.Paths;

public class TestCLass {

    public static void main(String[] args) {
        final Path path = Paths.get("com", "repo:access","resource");
        //final Path path = Paths.get("com", "repoaccess","resource"); //Output - com/repoaccess/resource
        System.out.println(path);
    }
}

Exception例外

Exception in thread "main" java.nio.file.InvalidPathException: Illegal char <:> at index 8: com\repo:access\resource
    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)

Is there any API to access colon(:) and any other special character?是否有任何 API 可以访问冒号 (:) 和任何其他特殊字符?

As far as I know, neither Windows nor Linux allow ":" to be put in a file name.据我所知,Windows 和 Linux 都不允许在文件名中添加“:”。 That's why Java throws InvalidPathException for such a path/file name.这就是 Java 为这样的路径/文件名抛出InvalidPathException的原因。 There's no API to work around a restriction imposed by the file system.没有 API 可以解决文件系统强加的限制。

暂无
暂无

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

相关问题 java.nio.file.InvalidPathException - java.nio.file.InvalidPathException java.nio.file.InvalidPathException:使用国家字符时格式错误的输入或输入包含不可映射的字符 - java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters when using national characters 带有getPath的java.nio.file.InvalidPathException - java.nio.file.InvalidPathException with getPath 系统错误:java.nio.file.InvalidPathException: - SystemError: java.nio.file.InvalidPathException: 线程“ main”中的异常java.nio.file.InvalidPathException:UNC路径缺少主机名:/ \\ / - Exception in thread “main” java.nio.file.InvalidPathException: UNC path is missing hostname: /\/ 使用闭包编译器格式化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 为什么这会抛出 java.nio.file.InvalidPathException? - Why does this throw java.nio.file.InvalidPathException? 遇到java.nio.file.InvalidPathException:非法char &lt;:&gt; - Encountering java.nio.file.InvalidPathException: Illegal char <:> java.nio.file.InvalidPathException:索引 2 处的非法字符 <:>: - java.nio.file.InvalidPathException: Illegal char <:> at index 2: Magnolia 5.4在发布/取消发布时升级java.nio.file.InvalidPathException - Magnolia 5.4 upgrade java.nio.file.InvalidPathException on publishing/unpublishing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM