Copy a directory from a jar file

Posted by Macarse on Stack Overflow See other posts from Stack Overflow or by Macarse
Published on 2009-09-06T21:46:00Z Indexed on 2010/06/07 23:42 UTC
Read the original article Hit count: 323

Filed under:
|
|

Hi.

I recently finished and application and created a jar file.

One of my classes creates an output directory populating it with files from it's resource.

The code is something like this:

// Copy files from dir "template" in this class resource to output.
private void createOutput(File output) throws IOException {

    File template = new File(FileHelper.URL2Path(getClass().getResource("template")));
    FileHelper.copyDirectory(template, output);
}

The problem is that now that I am running for a jar, this doesn't work.

I tried without luck:

While writting this I was thinking about instead of having a template dir in the resource path having a zip file of it. Doing it this way I could get the file as an inputStream and unzip it where I need to. But I am not sure if it's the correct way.

Thanks for reading!

© Stack Overflow or respective owner

Related posts about java

Related posts about jar