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
Solved

Read file within same JAR as applet

Posted on 2002-05-28
6
687 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 92

Accepted Solution

by:
objects earned 100 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

856 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