URLDemo.java
Java class documentation URL
Wikipedia article URL (Uniform Resource Locator)
// Demonstrate URL. import java.net.*; class URLDemo { public static void main(String[] args) { String str1 = "http://www.mhhe.com:80/index.html"; String str2 = "http://www.udayton.edu:80/index.html"; try { URL url = new URL(str2); System.out.println("Protocol: " + url.getProtocol()); System.out.println("Port: " + url.getPort()); System.out.println("Host: " + url.getHost()); System.out.println("File: " + url.getFile()); } catch (MalformedURLException exc) { System.out.println("Invalid URL: " + exc); } } }
Protocol: http Port: 80 Host: www.udayton.edu File: /index.html
Maintained by John Loomis, updated Wed Nov 14 13:39:37 2012