I want to include a folder in my project (which will be a JAR or a plugin) to copy&paste it somewhere at runtime. I tried the following:
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);
But I got a java.io.FileNotFoundException "Access denied" because a folder can't be written like that. If it was a file, it would work.
Note: How can I get a resource "Folder" from inside my jar File? didn't solve my problem because I don't want to list the contained files, I only want to copy&paste the whole folder. java.io.FileNotFoundException: (Access is denied) didn't either because I don't want to read the folder dest but to write it from a stream, since the embedded folder src can't be referenced in a File object.