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); } } |
Friday, December 9, 2011
THE FUTURE JAVA CODER
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment