import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;


public class URLExample {
	public static void main(String[] args) {
		
		URL url = null;
		try {
			url = new URL("http://www.google.com");
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		
		String result = "";
		
		URLConnection conn = null;
		try {
			conn = url.openConnection();
			conn.connect();
			
			BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
			byte[] buffer = new byte[5000];
			int length = -1;
			while ((length = in.read(buffer)) != -1) {
				result += new String(buffer, 0, length);
			}
			System.out.println(result);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

