By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,541 Members | 1,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,541 IT Pros & Developers. It's quick & easy.

Converting URL to URI objects

P: n/a
ccr
Hi. I need to load data from my classpath through the Class
getResource(...) method. It returns a URL object. But I also need to load
this into a resource into a File object. Unfortunately, the closest File
constructor accepts only a URI object.

How do I convert a URL object to a URI object? The javadocs say these two
classes are related but I can't find anyway to convert a URL to a URI.


Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"ccr" <no****@nospam.no> wrote in message
news:Oi*******************@news.easynews.com...

Hi. I need to load data from my classpath through the Class
getResource(...) method. It returns a URL object. But I also need to load this into a resource into a File object. Unfortunately, the closest File
constructor accepts only a URI object.

How do I convert a URL object to a URI object? The javadocs say these two
classes are related but I can't find anyway to convert a URL to a URI.


Try:

URI uri; URL url;
...
try { uri = new URI(url.toString()); }
catch (URISyntaxException e) { ... }
...

I hope this helps.

Anthony Borla
Jul 17 '05 #2

P: n/a
ccr
Thanks Anthony. It appears to be working with my files outside of a jar
archive. I hope it will work when I jar up my application later but it
looks promising so far. :)
"Anthony Borla" <aj*****@bigpond.com> wrote in message
news:EX********************@news-server.bigpond.net.au...
"ccr" <no****@nospam.no> wrote in message
news:Oi*******************@news.easynews.com...

Hi. I need to load data from my classpath through the Class
getResource(...) method. It returns a URL object. But I also need to

load
this into a resource into a File object. Unfortunately, the closest File constructor accepts only a URI object.

How do I convert a URL object to a URI object? The javadocs say these two classes are related but I can't find anyway to convert a URL to a URI.


Try:

URI uri; URL url;
...
try { uri = new URI(url.toString()); }
catch (URISyntaxException e) { ... }
...

I hope this helps.

Anthony Borla

Jul 17 '05 #3

P: 1
hi,

This is not working when I craete a jar and execute it.

Is there any other way to convert URL to URI???

Thanks
~neel
May 2 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.