Re: class checksums

From: David Zimmerman (foo_at_junk.bar)
Date: 12/12/03


Date: Fri, 12 Dec 2003 12:23:01 GMT


Michael Fairbank wrote:
>>That's a two-liner.
>>If you have an Object, you can invoke its getClass() method which gives
>>you access via getName() to its class name and a getResourceAsStream()
>
> method
>
>>that will automatically look in the right location. All you need to do is
>>remove the package component from the name.
>
>
> I'm having problems with this. I cannot get the "resource as stream"
> functions to work when the filename ends in ".class". For example, the
> following code prints "null"
>
> String className=obj.getClass().getName();
> className=className+".class";
> InputStream in=ClassLoader.getSystemResourceAsStream(className);
> System.out.println(className+" in="+(in==null?"null":in.toString()));
>

You need to change the '.'s in the classname to '/'s, the file seperator
in resources



Relevant Pages

  • Re: Zugriff auf Resourcen
    ... Kombinationen von getClass(), getClassLoader, relativem und ... Jein, es geht, aber nur auf Umwegen. ... Mittels getResourceAsStream geht es nicht. ... IMHO ist das aber ziemlich umständlich und man sollte dort über den ServletContext gehen. ...
    (de.comp.lang.java)
  • Re: Any way to use getResourceAsStream() from static context?
    ... getResourceAsStream() in the mainmethod without loading a class and calling getClass(). ...
    (comp.lang.java.help)