Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get resource path

Tags:

java

path

created a new folder "resources" with all my images in eclipse. I added this folder to the class path.

Now i tried to access this images

URL url = new URL("imageA");

I also tried

URL url = new URL("resources/imageA");

Both doesnt't work. What is wrong?

Sincerely Christian

like image 457
Christian Avatar asked Jun 29 '10 11:06

Christian


2 Answers

If you are loading from your classpath you should do something like this

InputSteam is =  this.getClass().getClassLoader().getResourceAsStream("resources/myimage.png")
like image 87
Chuk Lee Avatar answered Nov 13 '22 23:11

Chuk Lee


I believe what you want to use are e.g.:

  • URL Class.getResource(String name)
  • InputStream Class.getResourceAsStream(String name).

See also

  • devx.com - Loading resources with the getResource() method
  • stackoverflow.com - Search [java] getResource
like image 43
polygenelubricants Avatar answered Nov 14 '22 00:11

polygenelubricants