title: Copy directory from a jar file
body: <p>I have recently developed an application and created the jar file.</p>
  
  <p>One of my classes creates an output directory, populating it with files from its resource.</p>
  
  <p>My code is something like this:</p>
  
  <pre><code>// 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);
  }
  </code></pre>
  
  <p>Unfortunately this doesn't work.</p>
  
  <p>I tried the following without luck:</p>
  
  <ul>
  <li><p>Using Streams to solve similar stuff
  on other classes but it doesn't work
  with dirs. Code was similar to
  <a href="http://www.exampledepot.com/egs/java.io/CopyFile.html" rel="noreferrer">http://www.exampledepot.com/egs/java.io/CopyFile.html</a></p></li>
  <li><p>Creating the File template with <code>new File(getClass().getResource("template").toUri())</code></p></li>
  </ul>
  
  <p>While writing 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.</p>