Sunday, March 01, 2009

Converting URI to URL

This is a sample program to convert URI (Uniform Resource Identifiers) to URL (Uniform Resource Locator).

import java.net.*;
public class DemoConvertURItoURL {
public static void main(String[] args) {

URI uri = null;
URL url = null;
String uriString = "http://www.google.co.in/";
try {
uri = new URI(uriString);
}
catch (URISyntaxException e) {
e.printStackTrace();
}
try {

url = uri.toURL();
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
System.out.println("Original URI : " + uri);

System.out.println("Converted URL : " + url);
}

}

source: java-tips.org

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory