Here you can find the source of downloadToString(String url)
public static String downloadToString(String url)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.*; public class Main { public static String downloadToString(String url) { URL website = null;/*w w w. ja v a 2 s . c om*/ try { website = new URL(url); } catch (MalformedURLException e) { System.out.println("Couldn't connect to " + url); return null; } URLConnection connection = null; try { connection = website.openConnection(); } catch (IOException e) { System.out.println("Couldn't connect to " + url); return null; } BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(connection.getInputStream())); } catch (IOException e) { System.out.println("Couldn't read " + url); return null; } StringBuilder response = new StringBuilder(); String inputLine; try { while ((inputLine = in.readLine()) != null) response.append(inputLine); } catch (IOException e) { System.out.println("Trouble reading " + url); return null; } try { in.close(); } catch (IOException e) { System.out.println("Couldn't close connection to " + url); } return response.toString(); } }