Here you can find the source of readStringFromStream(InputStream stream, Charset charset)
static String readStringFromStream(InputStream stream, Charset charset) throws IOException
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; public class Main { static String readStringFromStream(InputStream stream, Charset charset) throws IOException { StringBuilder stringBuilder = new StringBuilder(); Reader reader = new InputStreamReader(stream, charset); char[] buffer = new char[1024]; while (true) { int res = reader.read(buffer); if (res == -1) { break; }//from w ww .ja va 2 s .com stringBuilder.append(buffer, 0, res); } reader.close(); stream.close(); return stringBuilder.toString(); } }