Here you can find the source of streamToString(InputStream in, String charset)
public static String streamToString(InputStream in, String charset)
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class Main { public static String streamToString(InputStream in, String charset) { try {// w ww . j a v a 2s .c om BufferedReader reader = new BufferedReader( new InputStreamReader(in, charset)); StringBuffer buffer = new StringBuffer(); String line = null; try { while ((line = reader.readLine()) != null) { buffer.append(line); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return buffer.toString(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; } }