Here you can find the source of InputStreamToString(InputStream in)
public static String InputStreamToString(InputStream in)
//package com.java2s; 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 in) { String result = null;/*from w ww. j a va 2 s . c o m*/ ByteArrayOutputStream outStream = null; if (in != null) { try { outStream = new ByteArrayOutputStream(); byte[] data = new byte[BUFFER_SIZE]; int count = -1; while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) outStream.write(data, 0, count); data = null; result = new String(outStream.toByteArray(), "utf-8"); } catch (Exception e) { e.printStackTrace(); } finally { try { outStream.close(); } catch (IOException e) { } } } return result; } }