Here you can find the source of readString(InputStream in, String charset)
public static String readString(InputStream in, String charset)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; public class Main { public static String readString(InputStream in) { return new String(readAll(in)); }// w ww. j ava2 s . co m public static String readString(InputStream in, String charset) { try { return new String(readAll(in), charset); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } public static String readString(InputStream in, Charset charset) { return new String(readAll(in), charset); } public static byte[] readAll(InputStream in) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); copyTo(in, baos); return baos.toByteArray(); } public static void copyTo(InputStream in, OutputStream out) { try { byte[] arr = new byte[1024]; int read; while ((read = in.read(arr)) != -1) { out.write(arr, 0, read); } } catch (IOException e) { throw new RuntimeException(e); } } }