Solved

Read file within same JAR as applet

Posted on 2002-05-28
6
683 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 24

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 24

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now