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".
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".
You can read any type of file from your jar.
Use the Class method getResourceAsStream() to open the file.
Use the Class method getResourceAsStream() to open the file.
ASKER
Does anyone have some example code for either of the two solutions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi!
Look at this web page :
http://www.onjava.com/pub/a/onjava/2001/04/12/signing_jar.html?page=3
or this
http://www.superliminal.com/sources/JarLoader.java.html
Hope these examples help you.
Regards,
Tomas Helgi
Look at this web page :
http://www.onjava.com/pub/a/onjava/2001/04/12/signing_jar.html?page=3
or this
http://www.superliminal.com/sources/JarLoader.java.html
Hope these examples help you.
Regards,
Tomas Helgi
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