Saturday, September 14, 2013

Networking : Lesson 03 - URLConnection class


Networking : Lesson 03 - URLConnection class

package Networking;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

/**
* @author sanjeeva
*
* URLConncetion class represent a communication link between the URL and the application.
*
* The class can be used to read and write data to the specified resource refer by the URL.
*/
public class URLConnectionClass {

      /**
      * @param args
      */
      public static void main(String[] args) {

            try {
                   URL url = new URL("http://educationjavacode.blogspot.com/search/label/Networking%20%3A%20Lesson%2001%20%E2%80%93%20Socket%20Programming");

                   URLConnection urlConnection = url.openConnection();
                   InputStream inputStream = urlConnection.getInputStream();

                   int i;
                   while((i=inputStream.read())!=-1){
                          System.out.print((char)i);
                   }
             }catch (Exception e) {
                   // TODO: handle exception
             }
      }
}