Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readStream(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024 * 10]; int readlen; while ((readlen = is.read(buf)) >= 0) { baos.write(buf, 0, readlen); } baos.close(); return baos.toByteArray(); } }