Here you can find the source of inputStream2String(InputStream is)
public static String inputStream2String(InputStream is) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static String inputStream2String(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int i = -1; while ((i = is.read()) != -1) { baos.write(i);//ww w . j av a 2 s . co m } byte[] lens = baos.toByteArray(); String result = new String(lens, "UTF-8"); return result; } }