Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Read file within same JAR as applet

Posted on 2002-05-28
6
Medium Priority
?
702 Views
Last Modified: 2011-10-03
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".
0
Comment
Question by:BOINGED
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 7038835
  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
0
 
LVL 92

Expert Comment

by:objects
ID: 7038856
You can read any type of file from your jar.
Use the Class method getResourceAsStream() to open the file.
0
 

Author Comment

by:BOINGED
ID: 7055937
Does anyone have some example code for either of the two solutions?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 7057949
InputStream in = getClass().getResourceAsStream(resourcename);
// then simply read your file from input stream
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 7058806
 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
0
 
LVL 92

Expert Comment

by:objects
ID: 7273191
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question