How to get real path of an image in Java?

get path of image file that is outside the project in java

sasola at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

See: http://stackoverflow.com/questions/2343187/loading-resources-using-getclass-getresource Basically when you use getResource it is expecting the file to be on the Classpath. There is also a constructor for ImageIcon that takes a String filename, so you can pass the path to the Icon file directly. Check out the http://docs.oracle.com/javase/7/docs/api/javax/swing/ImageIcon.html#ImageIcon%28java.lang.String%29

DaveJohnston

You can try using a File, like so: File f = new File("C:\\folder\\stuff\\MyFile.class");

f1dave

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.