Here you can find the source of getStreamAsString(InputStream input, String charset)
private static String getStreamAsString(InputStream input, String charset) throws IOException
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { private static String getStreamAsString(InputStream input, String charset) throws IOException { StringBuilder sb = new StringBuilder(); BufferedReader bf = null; try {//from www .java2 s .c o m bf = new BufferedReader(new InputStreamReader(input, charset)); String str; while ((str = bf.readLine()) != null) { sb.append(str); } return sb.toString(); } finally { if (bf != null) { bf.close(); bf = null; } } } }