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.