import java.net.*; /** Read a URL from the command line, then print * the various components. * * Taken from Core Web Programming from * Prentice Hall and Sun Microsystems Press, * http://www.corewebprogramming.com/. * © 2001 Marty Hall and Larry Brown; * may be freely used or adapted. */ public class UrlTest { public static void main(String[] args) { if (args.length == 1) { try { URL url = new URL(args[0]); System.out.println ("URL: " + url.toExternalForm() + "\n" + " File: " + url.getFile() + "\n" + " Host: " + url.getHost() + "\n" + " Port: " + url.getPort() + "\n" + " Protocol: " + url.getProtocol() + "\n" + " Reference: " + url.getRef()); } catch(MalformedURLException mue) { System.out.println("Bad URL."); } } else System.out.println("Usage: UrlTest "); } }