Java tutorial
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static String streamToString(InputStream is, String encode) throws Exception { byte[] data = streamToBytes(is); return new String(data, encode); } public static byte[] streamToBytes(InputStream is) throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = is.read(buffer)) != -1) { os.write(buffer, 0, len); } return os.toByteArray(); } }