Here you can find the source of fetchUrl(String _url, String charset)
public static String fetchUrl(String _url, String charset)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; public class Main { public static String fetchUrl(String _url) { return fetchUrl(_url, null); }// w w w. java 2s . co m public static String fetchUrl(String _url, String charset) { BufferedReader reader = null; try { URL url = new URL(_url); if (charset == null) reader = new BufferedReader(new InputStreamReader(url.openStream())); else reader = new BufferedReader(new InputStreamReader(url.openStream(), charset)); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } return sb.toString(); } catch (Throwable e) { throw new RuntimeException(e); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } } public static String toString(Object obj) { if (null == obj) return null; return String.valueOf(obj); } }