Here you can find the source of InputStreamTOString(InputStream in)
public static String InputStreamTOString(InputStream in)
//package com.java2s; import java.io.*; public class Main { final static int BUFFER_SIZE = 4096; public static String InputStreamTOString(InputStream in) { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] data = new byte[BUFFER_SIZE]; String string = null;//from w w w. j a v a 2 s . c om int count = 0; try { while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) outStream.write(data, 0, count); } catch (IOException e) { e.printStackTrace(); } data = null; try { string = new String(outStream.toByteArray(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return string; } public static String InputStreamTOString(InputStream in, String encoding) { String string = null; ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] data = new byte[BUFFER_SIZE]; int count = -1; try { while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) outStream.write(data, 0, count); } catch (IOException e) { e.printStackTrace(); } data = null; try { string = new String(outStream.toByteArray(), encoding); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return string; } }