getResourceStream oddity

I'm working on a webapp and I've come across something that is puzzling me. I'm using getResourceStream to retrieve some XML configuration files at application startup. When I search for "/application.xml" it works, but when I search for "application.xml" it does not find it. Any ideas? Code sample below.

in = Application.class.getResourceAsStream("/" + fileName);//works

in = Application.class.getResourceAsStream(fileName);// does not work

[554 byte] By [kwellinga] at [2007-11-26 16:00:46]
# 1

I think that method exists in both Class and ClassLoader, and I'm not sure which one you're referring to. I think (but may be wrong) that the behavior is slightly different.

In at least one of them, I think that with the leading / means relative to classpath roots, and without it means relative to the level at which the current class was found. So if your current class is a.b.C, and "foo.xml" becomes equivalent to "/a/b/foo.xml." Or something to that effect.

jverda at 2007-7-8 22:22:16 > top of Java-index,Java Essentials,Java Programming...
# 2
leading with / means the path is absolute. From the roots of the class path specified by the class loader used to load the class that this method is called from.not using a / means relative to the class that is issueing the query.
dmbdmba at 2007-7-8 22:22:16 > top of Java-index,Java Essentials,Java Programming...
# 3

> In at least one of them, I think that with the

> leading / means relative to classpath roots, and

> without it means relative to the level at which the

> current class was found. So if your current class is

> a.b.C, and "foo.xml" becomes equivalent to

> "/a/b/foo.xml." Or something to that effect.

And the documentation says something to that effect, too. In rather obscure terminology, but that's what it says.

DrClapa at 2007-7-8 22:22:16 > top of Java-index,Java Essentials,Java Programming...
# 4

> > In at least one of them, I think that with the

> > leading / means relative to classpath roots, and

> > without it means relative to the level at which

> the

> > current class was found. So if your current class

> is

> > a.b.C, and "foo.xml" becomes equivalent to

> > "/a/b/foo.xml." Or something to that effect.

>

> And the documentation says something to that effect,

> too. In rather obscure terminology, but that's what

> it says.

**** Alzheimer's. I could've sworn I'd added the obligatory, "See the docs for details."

jverda at 2007-7-8 22:22:16 > top of Java-index,Java Essentials,Java Programming...