Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

getting file from jar

Thread view: 
alan jeeves - 10 Apr 2004 00:00 GMT
Hi,

I'm trying to read a file from the jar file my app is packaged in but i cant
get it to read the parent directory. It works when running just from the
class files - ie not packaged up.

I'm doing the following:
   URL url = LinkFollower.class.getResource("..\\helpdocs\\help.htm");

and in the jar i have the following file structure

other\LinkFollower.class
helpdocs\help.htm

But the url is allways null - can someone tell me why this might be. It
works if i have the helpdocs folder in the same directory as the
LinkFollower.class - but ill prefer not to have to do that way.

Im running WinXP and j2sdk 1.4.1_06

Thanks,

Alan.
Andrew Thompson - 10 Apr 2004 00:28 GMT
> I'm doing the following:
>     URL url = LinkFollower.class.getResource("..\\helpdocs\\help.htm");
[quoted text clipped - 3 lines]
> other\LinkFollower.class
> helpdocs\help.htm

No actually, you don't, the
structure might be..

other/LinkFollower.class
helpdocs/help.htm

Jar's _always_ use the forward slash.
Give that a try.  

Also, I don't think the '..' makes
any sense, Class.getResource()
ignores it AFAIR.

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Roedy Green - 10 Apr 2004 00:32 GMT
>URL url = LinkFollower.class.getResource("..\\helpdocs\\help.htm");

That is not a valid url to getResource.  It must not start with .. or
/. It must contain / internally.  It must be relative.  Think of it as
the name inside the jar.

See http://mindprod.com/jgloss/image.html for a fuller explanation.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.