Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { private static final int BYTE_ARRAY_LENTH = 2048; public static String inputStream2String(InputStream in) throws Exception { return new String(inputStream2ByteArray(in)); } public static byte[] inputStream2ByteArray(InputStream in) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[BYTE_ARRAY_LENTH]; int len = -1; while ((len = in.read(buf)) != -1) { bos.write(buf, 0, len); } return bos.toByteArray(); } }