Converting Between a URL and a URI

URI uri = null; URL url = null; // Create a URI try { uri = new URI("file://D:/almanac1.4/Ex1.java"); } catch (URISyntaxException e) { } // Convert an absolute URI to a URL try { url = uri.toURL(); } catch (IllegalArgumentException e) { // URI was not absolute } catch (MalformedURLException e) { } // Convert a URL to a URI try { uri = new URI(url.toString()); } catch (URISyntaxException e) { }

Comments

2 Mar 2010 - 9:03am by Anonymous (not verified)

// Convert an URL tp an URI:
uri = url.toURI();

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.