Here you can find the source of getContentFromURL(String url)
public static String getContentFromURL(String url)
//package com.java2s; /**//from w w w .j av a2 s . c o m * This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 * International License. http://creativecommons.org/licenses/by-nd/4.0/ * * @author Wruczek */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static String getContentFromURL(String url) { try { return getContentFromURL(new URL(url)); } catch (Exception e) { } return null; } public static String getContentFromURL(URL url) { try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); conn.setDoOutput(true); Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); StringBuilder sb = new StringBuilder(); for (int c; (c = in.read()) >= 0;) sb.append((char) c); return sb.toString().trim(); } catch (IOException e) { } return null; } }