如何复制和粘贴嵌入的文件夹

时间:2015-09-23 08:14:04

标签: java directory copy-paste

我希望在我的项目中包含一个文件夹(它将是一个JAR或插件),以便在运行时将其复制并粘贴到某处。我尝试了以下方法:

private static void copyStream(InputStream i, OutputStream o) throws IOException {
    byte[] buffer = new byte[1024];
    int bytesRead;
    while((bytesRead = i.read(buffer)) != -1)
        o.write(buffer, 0, bytesRead);
}

InputStream is = getClass().getResourceAsStream(src);
FileOutputStream fos = new FileOutputStream(dest); // error
copyStream(is, fos);

但是我得到了一个java.io.FileNotFoundException“拒绝访问”,因为文件夹不能这样写。如果它是一个文件,它会工作。

注意:How can I get a resource "Folder" from inside my jar File?没有解决我的问题,因为我不想列出包含的文件,我只想复制并粘贴整个文件夹。 java.io.FileNotFoundException: (Access is denied)也没有,因为我不想读取文件夹dest但是要从流中写入,因为嵌入文件夹src不能在File对象中引用。

0 个答案:

没有答案
相关问题