Here you can find the source of inStream2Str(InputStream inputStream, String encode)
public static String inStream2Str(InputStream inputStream, String encode)
//package com.java2s; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static String inStream2Str(InputStream inputStream, String encode) { String result = null;//from ww w . j a va 2 s . co m if (inputStream != null) { try { BufferedInputStream bis = new BufferedInputStream( inputStream); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int position = 0; while ((position = bis.read()) != -1) { baos.write((byte) position); } if (encode == null) { result = baos.toString(); } else { result = baos.toString(encode); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return result; } }