gpt4 book ai didi

java - 非法参数异常 : URI is not hierarchical when calling existing folder

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:34:38 42 4
gpt4 key购买 nike

我这样做:

private boolean createCopy(String targetDirectory, String[] dataSet, String fileName, boolean overwrite) throws IOException, URISyntaxException
{
fileName = "file:" + fileName.replace(" ","%20");
URI uri = new URI("file:" + targetDirectory);
Path dPath = Paths.get(uri);
//code
}

我得到这个异常:

Exception in thread "main" java.lang.IllegalArgumentException: URI is not hierarchical
at sun.nio.fs.WindowsUriSupport.fromUri(WindowsUriSupport.java:122)
at sun.nio.fs.WindowsFileSystemProvider.getPath(WindowsFileSystemProvider.java:92)
at java.nio.file.Paths.get(Paths.java:138)
...

Path dPath = Paths.get(uri);

行。有人知道这是为什么吗? targetDirectory 只是一个简单的文件夹,既不是JAR 也不是WAR 文件;如果我取消

URI uri = new URI("file:" + targetDirectory);

我刚刚明白

Exception in thread "main" java.nio.file.FileSystemNotFoundException: Provider "DRIVE_LETTER" not installed
at java.nio.file.Paths.get(Paths.java:147)
...

“DRIVE_LETTER” 最终变成类似“C”或“D”或“E”的东西。它是 targetDirectory 所在的驱动器。

编辑:

public static void main(String... args)
{
Path path = null;
try
{
Paths.get(new URI("file:E://HTML%20Processor//test//copies//"));
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
}

抛出完全相同的异常,因为您想知道确切的调用。

编辑:将文件放在任何其他驱动器上没有区别; USB 或 SATA 驱动器也没有区别。

最佳答案

应该是 file://而不是 file:

关于java - 非法参数异常 : URI is not hierarchical when calling existing folder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45555761/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com