|
How to convert 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/";
// Create a URI object
try {
uri = new URI(uriString);
} catch (URISyntaxException e) {
e.printStackTrace();
}
// Convert the absolute URI to a URL object
try {
url = uri.toURL();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
//print the URI and URL
System.out.println("Original URI : " + uri);
System.out.println("Converted URL : " + url);
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.