Here you can find the source of writeStreamToString(InputStream is, String charsetName)
public static String writeStreamToString(InputStream is, String charsetName) throws IOException
//package com.java2s; //License from project: LGPL import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; public class Main { public static String writeStreamToString(InputStream is, String charsetName) throws IOException { return writeStreamToString(is, Charset.forName(charsetName)); }/*from www . ja v a 2 s . c o m*/ public static String writeStreamToString(InputStream is) throws IOException { return writeStreamToString(is, Charset.defaultCharset()); } public static String writeStreamToString(InputStream is, Charset charset) throws IOException { BufferedReader br = null; StringBuffer result = new StringBuffer(); try { InputStream in = new DataInputStream(is); br = new BufferedReader(new InputStreamReader(in, charset)); String strLine; // Read File Line By Line while ((strLine = br.readLine()) != null) { result.append(strLine + "\n"); } } finally { br.close(); } return result.toString(); } }