/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ import java.net.URL; import java.net.MalformedURLException; public class URLConstruction { public static void main(String [] argv) { try { URL [] u = { new URL("http://www.fh-wedel.de/~si/index.html"), new URL("http", "www.fh-wedel.de", "/~si/index.html"), new URL("http", "www.fh-wedel.de", 80, "/~si/index.html#start"), null, new URL("file://localhost/etc/passwd"), new URL("file", "localhost", "/etc/passwd") }; u[3] = new URL(u[0], "document.html"); for (int i = 0; i < u.length; ++i ) { System.out.println(u[i] + "\n " + u[i].getProtocol() + "\n " + u[i].getHost() + "\n " + u[i].getPort() + "\n " + u[i].getFile() + "\n " + u[i].getRef() + "\n"); } } catch (MalformedURLException e) { System.out.println(e); } } }