title: How to get .jar resources path?
body: <p>I'm using a custom method to get pictures from the <code>resources/</code> folder. The hardcoded path works well when programming during production (<code>src/main/resources/</code>). However when delivering, I would need to make this path relative to the .jar root. So I made this.</p>
  <pre class="lang-java prettyprint-override"><code>public static Image getImageFromFile(String file)
  {
      Image image = null;
      try
      {
          String path = FileUtils.class.getClassLoader().getResource(file).toExternalForm();
          System.out.println(path);
  
          File pathToFile = new File(path);
          image = ImageIO.read(pathToFile);
      }
      catch (IOException ex) {ex.printStackTrace();}
      return image;
  }
  </code></pre>
  <pre class="lang-java prettyprint-override"><code>file:/C:/Users/Hugo/Desktop/Hugo/Java%20Workspace/ClashBot/bin/main/icons/level-label.png
  javax.imageio.IIOException: Can't read input file!
      at javax.imageio.ImageIO.read(Unknown Source)
      at com.lycoon.clashbot.utils.FileUtils.getImageFromFile(FileUtils.java:55)
  </code></pre>
  <p>The printed path is valid and points to the corresponding picture. However, the program raises an IOException.<br><br>
  Why can't it find the file?</p>