Here you can find the source of getStringFromConnection( HttpURLConnection connection)
public static String getStringFromConnection( HttpURLConnection connection) throws IOException
//package com.java2s; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; public class Main { public static String getStringFromConnection( HttpURLConnection connection) throws IOException { InputStream inputStream = new BufferedInputStream( connection.getInputStream()); String jsonString = convertStreamToString(inputStream); inputStream.close();//from w w w . j a v a2 s .c o m return jsonString; } private static String convertStreamToString(InputStream inputStream) { BufferedReader reader = new BufferedReader(new InputStreamReader( inputStream), 1024); StringBuilder stringBuilder = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { stringBuilder.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return stringBuilder.toString(); } }