title: How do I reference a resource in Java?
body: <p>I need to read a file in my code.  It physically resides here:</p>
  
  <pre><code>C:\eclipseWorkspace\ProjectA\src\com\company\somePackage\MyFile.txt
  </code></pre>
  
  <p>I've put it in a source package so that when I create a runnable jar file (Export->Runnable JAR file) it gets included in the jar.  Originally I had it in the project root (and also tried a normal sub folder), but the export wasn't including it in the jar.</p>
  
  <p>If in my code I do: </p>
  
  <pre><code>File myFile = new File("com\\company\\somePackage\\MyFile.txt");
  </code></pre>
  
  <p>the jar file correctly locates the file, but running locally (Run As->Java Main application) throws a file not found exception because it expects it to be:</p>
  
  <pre><code>File myFile = new File("src\\com\\company\\somePackage\\MyFile.txt");
  </code></pre>
  
  <p>But this fails in my jar file.  So my question is, how do I make this concept work for both running locally and in my jar file?</p>