Here you can find the source of slurpURL(URL u, String encoding)
public static String slurpURL(URL u, String encoding) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.SocketTimeoutException; import java.net.URL; import java.net.URLConnection; public class Main { /**/*from www .j a v a 2s .co m*/ * Returns all the text at the given URL. */ public static String slurpURL(URL u, String encoding) throws IOException { String lineSeparator = System.getProperty("line.separator"); URLConnection uc = u.openConnection(); uc.setReadTimeout(30000); InputStream is; try { is = uc.getInputStream(); } catch (SocketTimeoutException e) { // e.printStackTrace(); System.err.println("Time out. Return empty string"); return ""; } BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding)); String temp; StringBuilder buff = new StringBuilder(16000); // make biggish while ((temp = br.readLine()) != null) { buff.append(temp); buff.append(lineSeparator); } br.close(); return buff.toString(); } /** * Returns all the text at the given URL. */ public static String slurpURL(URL u) throws IOException { String lineSeparator = System.getProperty("line.separator"); URLConnection uc = u.openConnection(); InputStream is = uc.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String temp; StringBuilder buff = new StringBuilder(16000); // make biggish while ((temp = br.readLine()) != null) { buff.append(temp); buff.append(lineSeparator); } br.close(); return buff.toString(); } /** * Returns all the text at the given URL. */ public static String slurpURL(String path) throws Exception { return slurpURL(new URL(path)); } }