我有一個在運行時創建的zip文件,我需要將其複製到另一個目錄,但是每當我運行我的代碼時,我都會得到一個DirectoryNotEmptyException
。我需要指定一些額外的參數來複制到非空目錄嗎?如何用Java複製zip文件
這裏的佈局
Path sourceZip = new File(path).toPath();
String destinDir = new File(System.getProperty("user.dir")).getParent();
Path target = Paths.get(destinDir);
try {
Files.copy(sourceZip, target, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) //DirectoryNotEmptyException occurs here
{}
你需要做的迭代/遞歸IE:一次複製一個文件過來。查看Apache的FileUtils庫。 – proulxs 2014-09-26 18:26:52
看到這個答案:http://stackoverflow.com/a/1946311/2514228作者建議複製zip文件更容易做爲讀/寫字節。 – 2014-09-26 18:28:31
@proulxs好吧,那就是我所害怕的,我希望自從它被壓縮後,它會將它作爲一個「文件」而不是目錄來讀取,但唉 – sreya 2014-09-26 18:30:57