title: Java 7: get Path of resource (as object of type Path)
body: <p>I'm using the features of Java 7 to read in a file. For that purpose I need an object of type <code>Path</code>. In my code, I use the <code>getResource()</code> function to get the relative path (of type <code>URL</code>) to a file. </p>
  
  <p>However, now I have the problem that I don't really now how to get from an object of type <code>URL</code> to an object of type <code>Path</code> easily (<strong>without</strong> having to go through castings to e.g. to <code>URI</code> then to <code>File</code> and from that to <code>Path</code>)?</p>
  
  <p>Here an example to show you what I would like to do:</p>
  
  <pre><code>URL url = getClass().getResource("file.txt");
  Path path = (new File(url.toURI())).toPath(); //is there an easier way?
  List&lt;String&gt; list = Files.readAllLines(path, Charset.defaultCharset());
  </code></pre>
  
  <p>So is there an easier way to achieve that and not having to do that code mess on line 2?</p>