import java.io.*; import java.net.*; public class URLtest { public static void main(String argv[]) throws Exception { URL u = new URL(argv[0]); // argv is in the form "http://www.yahoo.com/" URLConnection uC = u.openConnection(); // connet to the site // casting getContent() to BufferedInputStream System.out.println("port " + u.getPort()); BufferedInputStream ins = (BufferedInputStream) u.getContent(); InputStreamReader isr = new InputStreamReader(ins); BufferedReader remote = new BufferedReader(isr); String line = new String(); line = remote.readLine(); System.out.print(" first line :::::: "); System.out.println(line); line = remote.readLine(); System.out.print(" second line :::::: "); System.out.println(line); line = remote.readLine(); System.out.print(" second line :::::: "); System.out.println(line); System.out.println(" more lines ..."); System.out.println(remote.readLine()); System.out.println(remote.readLine()); System.out.println(remote.readLine()); System.out.println(remote.readLine()); System.out.println(remote.readLine()); System.out.println(remote.readLine()); System.out.println(remote.readLine()); System.out.println(remote.readLine()); System.out.println(" host : " + u.getHost()); System.out.println(" protocol : " + u.getProtocol()); System.out.println(" port : " + u.getPort()); System.out.println(" allow interaction : " + uC.getAllowUserInteraction()); System.out.println(" allow interaction default : " + uC.getDefaultAllowUserInteraction()); System.out.println("URL : " + uC.getURL()); System.out.println("header : " + uC.getHeaderField("http")); } }