• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extracting Images from the image jar file

 
shahabas shabeer
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In oreder to improve the performance of my applet I want to download the images as a jar file (say images.jar).
But when I tried to read the images from this jar file I am getting an exception
like this.
java.util.zip.ZipException: No such file or directory
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:112)
at java.util.jar.JarFile.<init>(JarFile.java:127)
at java.util.jar.JarFile.<init>(JarFile.java:65)

Here is few lines from my code which is trying to extract images from the jar.

JarFile jarfile = new JarFile("images.jar");

ZipEntry firstentry = jarfile.getEntry("images/xyz.gif");
int size= (int) firstentry.getSize();
...
...
The exception is thrown from the first line ( "JarFile jarfile = new JarFile("images.jar")").

In the archive attribute of my applet tag I am adding this jar file also..

<APPLET CODE = "abc.xyz.class" CODEBASE = "." ARCHIVE = "abc.jar,images.jar" ...

Please help me.
 
Joe Ess
Bartender
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JarFile constructor takes the name of a local file. This fails, of course, because your jar file is back on the server. You may be able to load the images individually through Class.getResourceAsStream() since the jar is in the classpath (well, ARCHIVE parameter). If that doesn't work you will have to create a URL back to the JAR file and use JarInputStream to load it.
 
shahabas shabeer
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for ur reply ..

I solved the problem using 'JarURLConnection' class.

Thanks..

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic