title: What's the difference between a Resource, URI, URL, Path and File in Java?
body: <p>I'm looking at a piece of Java code right now, and it takes a path as a String and gets its URL using <code>URL resource = ClassLoader.getSystemClassLoader().getResource(pathAsString);</code>, then calls <code>String path = resource.getPath()</code> and finally executes <code>new File(path);</code>. </p>
  
  <p>Oh, and there are also calls to <code>URL url = resource.toURI();</code> and <code>String file = resource.getFile()</code>.</p>
  
  <p>I'm totally confused right now - mostly because of the terminology, I guess. Can someone please walk me through the differences, or provide a few links to Dummy-proof material? Especially URI to URL and <em>Resource to File</em>? To me, it feels like they should be the same thing, respectively...</p>
  
  <p>The difference between <strong><code>getFile()</code></strong> and <strong><code>getPath()</code></strong> is explained here: <a href="https://stackoverflow.com/a/11928221/2018047">What's the difference between url.getFile() and getpath()?</a> (Interestingly they both seem to return Strings, which probably adds a whole lot to my state of mind...)</p>
  
  <p>Now, if I have a locator that references a class or package in a jar file, will those two (i.e. path an file strings) differ?</p>
  
  <p><code>resource.toString()</code> would give you <code>jar:file:/C:/path/to/my.jar!/com/example/</code>, after all (note the exclamation mark).</p>
  
  <p>Is the difference between <strong>URI</strong> and <strong>URL</strong> <em>in Java</em> that the former doesn't encode spaces? Cf. <a href="https://stackoverflow.com/a/6818370/2018047">Files, URIs, and URLs conflicting in Java</a> (This answer explains the <em>general, conceptual</em> difference between the two terms fairly well: <a href="https://stackoverflow.com/questions/176264/whats-the-difference-between-a-uri-and-a-url/1984225#1984225">URIs identify and URLs locate;</a>)</p>
  
  <p>Lastly - and most importantly - <strong>why do I need <code>File</code> object; why isn't a Resource (<code>URL</code>) enough?</strong> (And is there a Resource object?)</p>
  
  <p>Sorry if this question is a bit unorganized; it just reflects the confusion I have... :)</p>