[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform] Re: Loading resources with getResource

By the way, be careful with the resource name here.

If you don't put in a leading slash then it will automatically prefix the name with package name of the class.

For example:

package x.y.z;

public class MyClass {

public void somemethod() {

  URI url = MyClass.class.getResource("abc.txt");
}

}

In this case, it will actually look for the resource "/x/y/z/abc.txt".
In other words if it is a relative path it will look in the directory where MyClass is found.


If you knew exactly where it was at then you should use "/abc.txt" instead.

This has tripped me up many times. :-)

Raja Kannappan wrote:
Try MyClass.class.getResource(String resourceName) and make sure resource is on your classpath.


-- Thanks, Rich Kulp