Here you can find the source of fetchURLContents(String url)
public static String fetchURLContents(String url)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Main { public static String fetchURLContents(String url) { URL u;//from w ww . java 2 s .c om try { u = new URL(url); HttpURLConnection uc = (HttpURLConnection) u.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream())); String s; uc.setConnectTimeout(1000); uc.setReadTimeout(1000); in = new BufferedReader(new InputStreamReader(uc.getInputStream())); String ret = new String(); while ((s = in.readLine()) != null) { if (ret.length() > 0) ret += "\n"; ret += s; } return (ret); } catch (ConnectException ex) { //System.out.println("Connect exception"); } catch (MalformedURLException ex) { } catch (IOException ex) { } catch (Exception ex) { } return (null); } }