Re: How to load properties as resources?



On 30 Jan 2006 16:16:33 -0800, "Mr. Land" <graftonfot@xxxxxxxxx>
wrote, quoted or indirectly quoted someone who said :

>ClassLoader cl = SystemProperties.class.getClassLoader();
>if (null != cl)
>{
> InputStream is = cl.getResourceAsStream("Common.properties");
> ...more code to load properties from the stream
>}

I'd do it more directly with:

InputStream fis = MyApp.class.getResourceAsStream( "Common.properties"
);

Your way is going to get into trouble on two counts:

1. unsigned Applets are not permitted to tinker with Classloaders

2. the classloader for java.lang.SystemProperties is not necessarily
the same one used for finding your App and its resources.

see http://mindprod.com/jgloss/resource.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
.



Relevant Pages

  • Re: Tracing in Java
    ... available in the professional edition. ... You could write your own classloader that dumped the name of each ... class to a file at is loads. ... Canadian Mind Products, Roedy Green. ...
    (comp.lang.java.programmer)
  • Re: changing the classpath at runtime in code
    ... yes but it requires firing up a new classloader. ... Roedy Green Canadian Mind Products ...
    (comp.lang.java.programmer)
  • Re: Permanent Generation and garbage collection
    ... or any Object of a class loaded by that ClassLoader? ... Roedy Green Canadian Mind Products ... "You can have quality software, or you can have pointer arithmetic; but you cannot have both at the same time." ...
    (comp.lang.java.programmer)