JAR files reading list files

R

rob hadow

I have written an application which is a kind of search engine for a book.
I down loaded off the net the list files which contain the program listings
for the book.
So my application can allow a user to search for any program listing.

The application works.However I want to put it into a JAR together with the
lst files (list files), so that the application can be run by clicking on
the JAR.
I have got it run OK, but I have to have the lst files in the directory at
which the the JAR is executed from. I can't get the application to get the
list files from the JAR itself.

I have the class files and the list files in a package, all contained in the
JAR. I have used a manifest file.

How do I get my application to look for the list files in the JAR rather
than looking in the cuurent directory?

I would be grateful for any suggestions! I hope my problem makes sense!

Rob Hadow
 
R

rob hadow

Andrew

Thanks, I,ve looked at your web site. Do I use the method
Class.getResource(String name) ?

File dire=new File("listing.lst"); // listing.lst is the directory
containing the lst files
File file=new File(dire,theFile); // theFile is a string containing the lst
file within the directory
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);

Do I replace the first line with something like File dire=new
File(Class.getResource("listing.lst")); // ???

Rob Hadow
 
A

Andrew Thompson

On Fri, 21 May 2004 13:23:07 +0100, rob hadow wrote:

(comments all way to bottom)
....
Thanks, I,ve looked at your web site. Do I use the method
Class.getResource(String name) ?

Yes. You can check the JavaDocs* to see it returns an URL..
(* Good links)
Do I replace the first line with something like
File dire= new File(Class.getResource("listing.lst")); // ???

I think you are going in the wrong direction
using Files. You can do more with an URL
than a file object, so I have gotten into the
practise of not using Files unless they offer
a specific advantage.

With Jar's, for example, you can get an Enumeration
of the ZipEntries and use them to construct URL's
through which you can use an..
<http://www.physci.org/api.jsp?class=java.net.JarURLConnection>
To get the data..

HTH

Oh, and could I ask you to 'in-line post with trimming'
as I and some others do? It makes threads easier
to understand.. Follow link for further details.
<http://www.physci.org/codes/javafaq.jsp#netiquette>
 
R

rob hadow

"> > "Andrew Thompson" <[email protected]> wrote in message
I think you are going in the wrong direction
using Files. You can do more with an URL
than a file object, so I have gotten into the
practise of not using Files unless they offer
a specific advantage.

With Jar's, for example, you can get an Enumeration
of the ZipEntries and use them to construct URL's
through which you can use an..
<http://www.physci.org/api.jsp?class=java.net.JarURLConnection>
To get the data..

HTH

Oh, and could I ask you to 'in-line post with trimming'
as I and some others do? It makes threads easier
to understand.. Follow link for further details.
<http://www.physci.org/codes/javafaq.jsp#netiquette>

Thanks for the info. I am looking into using URLs instead of files, but am
not getting anywhere!.

But I am not able to import java.util.zip or java.util.jar, I
get...............

MyClass.java [12:1] cannot resolve symbol
symbol : class jar
location: package util
import java.util.jar;
^
Does this mean I don't have the classes? I have just upgraded from jdk1.3
to j2sdk1.4.2, by downloading j2sdk1.4.2_04 and Netbeans IDE, and assumed
all the Classes would be there. Does this mean I have a problem?

Is what I have done "in-line trimming" ?
Rob Hadow
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top