Here you can find the source of InputStreamToString(InputStream in, String charset)
public static String InputStreamToString(InputStream in, String charset) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { final static int BUFFER_SIZE = 4096; public static String InputStreamTOString(InputStream inputStream) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] data = new byte[BUFFER_SIZE]; String string = null;//from w w w . j av a2 s. com int count = 0; while ((count = inputStream.read(data, 0, BUFFER_SIZE)) != -1) { byteArrayOutputStream.write(data, 0, count); } string = new String(byteArrayOutputStream.toByteArray(), "UTF-8"); return string; } public static String InputStreamToString(InputStream in, String charset) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] data = new byte[BUFFER_SIZE]; String string = null; int count = 0; while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) { byteArrayOutputStream.write(data, 0, count); } string = new String(byteArrayOutputStream.toByteArray(), charset); return string; } }