Two Laptop Bag*
The moose likes Java in General and the fly likes Where does a class look for resources? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Where does a class look for resources?" Watch "Where does a class look for resources?" New topic
Author

Where does a class look for resources?

Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89

Hi all,

What is the location where the class loader searches for resources as in the following usage?

java.net.URL imgURL = getClass().getResource(path);


Thanks,

Colm
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#getResource%28java.lang.String%29
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Thanks..and by resources this can be anything such as other classes, files, images etc?

(For example, I want to use this to locate an image file so I can create an image icon to display on a panel....)



Colm
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

Yes. You can even use the class files themselves as resource:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Colm Dickson
Ranch Hand

Joined: Apr 04, 2009
Posts: 89
Thanks for your help and the useful link.

Colm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where does a class look for resources?