title: Displaying an image from resources in Java Swing
body: <p>I'm trying to display a simple png image using <strong>Java Swing</strong>. The image is stored inside the project folder, more precisely in: <code>~/Workspace/MyProject/res/logo.png</code>.</p>
  <p>Inside a class named <code>FirstAccess.java</code> that extends <code>JFrame</code> i therefore declared:</p>
  <pre><code>final BufferedImage myLogo = ImageIO.read(new File(&quot;../res/logo.png&quot;));
  final JLabel logoLabel = new JLabel(new ImageIcon(myLogo));
  // [...]
  </code></pre>
  <p>But this generates the following exception.</p>
  <blockquote>
  <p>Exception in thread &quot;main&quot; javax.imageio.IIOException: Can't read input file!</p>
  <p>at javax.imageio.ImageIO.read(ImageIO.java:1301)</p>
  <p>[...]</p>
  <p>Process finished with exit code 1</p>
  </blockquote>
  <p>What's the problem? Am I using the wrong path? Is there maybe some access privileges issue?</p>
  <p><strong>Note:</strong> <code>FirstAccess.java</code> is located exactly in <code>~/Workspace/MyProject/src/main/</code></p>
  <p><strong>Note2</strong>: I also tried with the path <code>&quot;~/Workspace/MyProject/res/logo.png&quot;</code> inside <code>new File()</code>... but still gives the same problem.</p>