title: Fetching a resource in Java main method
body: <p>I'm trying to open a resource in my Java application by calling <code>MainClass.class.getResource("/Resources/file.extension")</code> and passing it to File's constructor with <code>getPath()</code>. Next, when I initialize a new <code>FileInputStream</code> with the <code>File</code>, I get a <code>FileNotFoundException</code>. The complete stack trace looks this.</p>
  
  <pre><code>java.io.FileNotFoundException: E:\user\Documents\NetBeansProjects\Project name\build\classes\Resources\file.csv (The system cannot find the path specified)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:138)
      at my.secret.project.MainClass.main(MainClass.java:27)
  </code></pre>
  
  <p>Here's my code.</p>
  
  <pre><code>File file = new File(MainClass.class.getResource("/Resources/file.extension").getPath());
  
  ...
  
  InputStream in = new FileInputStream(file);
  </code></pre>