Here you can find the source of getContent(String urlStr)
public static String getContent(String urlStr)
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; public class Main { public static String getContent(String urlStr) { StringBuilder sb = new StringBuilder(); InputStreamReader inputStreamReader = null; BufferedReader br = null; try {/*w w w . ja v a 2 s . c o m*/ URL url = new URL(urlStr); URLConnection conn = url.openConnection(); inputStreamReader = new InputStreamReader(conn.getInputStream()); br = new BufferedReader(inputStreamReader); String line = null; while ((line = br.readLine()) != null) { sb.append(line); } } catch (Exception e) { throw new RuntimeException("Url connection failed:" + urlStr, e); } finally { if (inputStreamReader != null) { try { inputStreamReader.close(); } catch (IOException e) { // Ignore } } if (br != null) { try { br.close(); } catch (IOException e) { // Ignore } } } return sb.toString(); } }