Here you can find the source of getURL(final URL url)
public static String getURL(final URL url) throws IOException
//package com.java2s; // Use and redistribution of this file is governed by the license terms in import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class Main { private static String FF_UA = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008111317 Ubuntu/8.04 (hardy) Firefox/3.0.4"; public static String getURL(final URL url) throws IOException { final HttpURLConnection conn = connect(url, false); final StringBuilder content = new StringBuilder(); final InputStreamReader in = new InputStreamReader(conn.getInputStream(), "UTF-8"); final char[] buff = new char[1024]; while (true) { final int blen = in.read(buff); if (blen < 0) { break; }/* www . java2 s . co m*/ content.append(buff, 0, blen); } in.close(); conn.disconnect(); return content.toString(); } public static HttpURLConnection connect(final URL url, final boolean output) throws IOException { final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("User-Agent", FF_UA); conn.setConnectTimeout(10000); // 10 seconds is reasonable conn.setReadTimeout(5000); // 5 seconds is reasonable conn.setDoOutput(output); conn.connect(); return conn; } }