Here you can find the source of getStreamAsString(InputStream stream, String charset)
private static String getStreamAsString(InputStream stream, String charset) throws IOException
//package com.java2s; import java.io.*; public class Main { private static String getStreamAsString(InputStream stream, String charset) throws IOException { try {/*from w w w. ja va 2s. c o m*/ BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset)); StringWriter writer = new StringWriter(); char[] chars = new char[256]; int count = 0; while ((count = reader.read(chars)) > 0) { writer.write(chars, 0, count); } return writer.toString(); } finally { if (stream != null) { stream.close(); } } } }