Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Load images and text file from jar file

Reply
Thread Tools

Load images and text file from jar file

 
 
Fuma
Guest
Posts: n/a
 
      06-20-2004
Hello,
I know this question has been asked before, but I cannot seem to
get the solutions posted to work. I am trying load to three images and
a text file from a jar file (this jar file is not in the classpath).
This jar file is the main jar file though. I intend for users to be
able to download this file to their desktop, double click, and run.
Unfortunately, I cannot figure out how to load the three images and
textfile from the jar file.

I have tried this solution but it doesnt want to work:

URL url = this.getClass().getResource("Teacher_online.jpg");
image = new ImageIcon( url );

and it says it can not file the file. And for the text file i have

URL url = this.getClass().getResource("config_student.ini");
ins = new InputStreamReader(url.openStream());
bufferedReader = new BufferedReader( ins );

If somone could shed some light on this problem i am having, i would
really appreciate it!

Thanks,
Chris
 
Reply With Quote
 
 
 
 
Filip Larsen
Guest
Posts: n/a
 
      06-20-2004
Fuma wrote

> I have tried this solution but it doesnt want to work:
>
> URL url = this.getClass().getResource("Teacher_online.jpg");
> image = new ImageIcon( url );
>
> and it says it can not file the file.


As the documentation says, the Class.getResource method will prepend the
"package path" to resource names that do not begin with a slash. In your
case, if file is placed as images/myfile.jpg in your jar-file you
probably want to call it with .getResource("/images/myfile.jpg").


Regards,
--
Filip Larsen


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java -cp a.jar -jar b.jar => Works on Windows, not on Debian cyberco Java 4 02-14-2006 06:27 AM
jaas.jar, jta.jar jdbc-stdext.jar missing from jdk1.5 RPM muttley Java 0 10-20-2005 02:40 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters Java 0 01-05-2005 10:59 PM
Differences of xercesImpl.jar, xercesImpl-J.jar, dom3-xercesImpl.jar ? Arnold Peters XML 0 01-05-2005 10:59 PM
how to disassembly a .jar file? how to see what are the classes inside the .jar file? lucy Java 6 09-07-2004 09:54 PM



Advertisments