title: Converting a jar-file URI to a File
body: <p>I need to access a configuration file from within my Jar, so I use:</p>
  
  <pre><code>URL configUrl = Object.class.getResource("/config.xml");
  </code></pre>
  
  <p>Now I need to convert URL into a File object, because that's what the ConfigurationFile object downstream needs for initialization. When I try this:</p>
  
  <pre><code>new File(configUrl.toURI())
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code> java.lang.IllegalArgumentException: URI is not hierarchical
  </code></pre>
  
  <p>When I try this:</p>
  
  <pre><code> new File(Thread.currentThread().getContextClassLoader().getResource("config.xml").getFile())
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>File does not exist: 'file:\E:\Apps\jarfile.jar!\config.xml'
  </code></pre>
  
  <p>NOTE: Unfortunately I must have a File object, on an InputStream.</p>