我在做這個的時候URI不分層:拋出:IllegalArgumentException:調用現有的文件夾
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驅動器也沒有區別。
所以,你可以提供給我們這個方法的調用嗎? – Anas
你能準確的告訴你目標目錄的路徑是什麼嗎?如果可能的話也提供完整的方法並傳遞給它的值。 java.nio.file.FileSystemNotFoundException表示驅動器不可訪問。您的代碼正在運行的計算機上是否安裝了指定的驅動器路徑? – Acewin
提供了一個簡單的方法,拋出相同的錯誤! – Chaoscrasher