No subject
Sat Nov 12 19:29:10 PST 2005
Netscape browsers don't support getResource() method, so you must use
getResourceAsStream() method. Here there is an example which extracts an
image from a JAR file:
InputStream is;
ByteArrayOutputStream baos;
Image img1;
is =
this.getClass().getResourceAsStream("/imagenes/ingresos_y_pagos.gif");
if (is == null)
System.out.println("No resource found");
baos = new ByteArrayOutputStream();
try
{
int c;
while((c = is.read()) >= 0)
baos.write(c);
img1 = getToolkit().createImage(baos.toByteArray());
}
catch(IOException e)
{
e.printStackTrace();
}
Mitch Gart wrote:
> I've got my .class files in a .jar file and have
> tried also putting some .gif images in the same .jar file.
> The applet is not finding them. If the directory
> images\*.gif is next to the .jar file, it works, but if
> the same directory is not present on disk and instead is
> just inside the .jar file, the images are not found.
>
> Is this a known problem? Is it a problem to all .jar files,
> or just an applet problem? Any workarounds? Any codebase
> or documentbase tricks? Thanks a lot,
>
> - Mitch
> - mgart at netegrity dot com
More information about the Advanced-java
mailing list