Link to home
Start Free TrialLog in
Avatar of BOINGED
BOINGED

asked on

Read file within same JAR as applet

Not sure if this is possible, but here goes.
I currently have a JAR'd applet that reads a data file using the URL class. This opens a separate http connection after the JAR has unpacked & applet started.
I have added the data file to the JAR but the applet still looks for the file separately.
Seeing as there's no problem loading images from within the JAR, is there any way to read any type of file this way?
I know that I could store the file as a .GIF image and use PixelGrabber but this is a "last resort".
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

  Hi!

Look at this API : http://java.sun.com/j2se/1.3/docs/api/java/util/jar/JarFile.html
There is a method (getInputStream ) which gives you access to the data in the specified file in the JARFile.
All you need to do is create an instance of the JARFile class.

Regards,
  Tomas Helgi
You can read any type of file from your jar.
Use the Class method getResourceAsStream() to open the file.
Avatar of BOINGED
BOINGED

ASKER

Does anyone have some example code for either of the two solutions?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial