Dear All
what is best :
to include resources (images,text files,etc) in the JAR
or to leave then as external
for both is there a difference between loading a resource from the JAR
and from the FileSystem
I need an example please.
Thanks
Arnaud Berger - 18 Apr 2005 13:45 GMT
Hi,
I can't say anything regarding performance .
However, here is what you want for getting resources from jar :
getClass().getClassLoader().getResourceAsStream(String name)
which gives you an InputStream from the resource.
or
getClass().getClassLoader().getResource(String name)
which gives you the URL of the resource.
if your jar contains image.gif inside a /images directory, name would be
"images/image.gif"
Note that getClass() can be called on an instance, you may also call the
class statically e.g :
MyApp.class.getClassLoader().getResourceAsStream(String name)
Regards,
Arnaud
> Dear All
>
[quoted text clipped - 9 lines]
>
> Thanks
Thomas Weidenfeller - 18 Apr 2005 14:51 GMT
> Dear All
>
> what is best :
>
> to include resources (images,text files,etc) in the JAR
> or to leave then as external
Include them in the jar. It makes it much easier to distribute an
application. The performance difference - if there is any - shouldn't
usually matter.
> for both is there a difference between loading a resource from the JAR
> and from the FileSystem
> I need an example please.
Why don't you write a small test program for yourself, and measure it?
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq