URL and/or ClassLoader problem [message #443671] |
Thu, 02 February 2006 13:27  |
Eclipse User |
|
|
|
R3.1.1, WinXP
So, I have a valid URL, that points to a valid directory, in one of my RCP plugins, containing some
"resource" (readonly) files; its string rep looks like this:
file:/c:/LOCATION/eclipse/workspace/com.foo.bar.some.plugin/ subdirectory/txt
Now, I want to create from that URL a valid URL for a specific file in that directory, so I can read
it, e.g., by calling fileURL.openStream(), and using the InputStream. So, I try this, where
"validURL" is my URL as above:
new URL(validURL, "filename.ext");
That fails! It gives me a URL that is bogus, whose String-rep is:
file:/c:/LOCATION/eclipse/workspace/com.foo.bar.some.plugin/ subdirectory/filename.ext
What does work is this:
new URL(validURL, "txt/" + "filename.ext");
But hardwiring in that "txt/" is clearly a Bad Thing -- so what am I doing wrong here?
thanks,
Paul
|
|
|
Re: URL and/or ClassLoader problem [message #453662 is a reply to message #443671] |
Mon, 07 August 2006 17:04  |
Eclipse User |
|
|
|
Finally I stumbled across the answer, recorded here for others who may run into the issue:
I was using this code (where the "xyz/" is replacing the "removed" last segment of the file-path):
new URL(url, "xyz/" + docID)
I've just discovered that this is the correct code:
new URL(url.getProtocol(), url.getHost(), url.getPort(), url.getFile() + '/' + docID)
HTH,
Paul
|
|
|
Powered by
FUDForum. Page generated in 0.04919 seconds