// Purpose. URLConnection - read import java.net.*; import java.io.*; public class URLConnectionReader { public static void main(String[] args) throws Exception { URL yahoo = new URL( "http://rampages.onramp.net/~huston" ); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); } } // Huston Home Page // //

Huston

// //

//

Favorite subjects:

// // Purpose. URLConnection - write // http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html import java.io.*; import java.net.*; public class URLConnectionWriter { public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println( "Usage: java URLConnectionReverse a_string" ); System.exit(1); } String str = URLEncoder.encode( args[0] ); URL url = new URL( "http://java.sun.com/cgi-bin/backwards" ); URLConnection connection = url.openConnection(); connection.setDoOutput( true ); PrintWriter out = new PrintWriter( connection.getOutputStream() ); out.println( "string=" + str ); out.close(); BufferedReader in = new BufferedReader( new InputStreamReader( connection.getInputStream() )); while ((str = in.readLine()) != null) System.out.println( str ); in.close(); } } // C:> java URLConnectionWriter "123 456 789" // 123 456 789 // reversed is: // // 987 654 321