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]

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.
> 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.
> > 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."