Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static byte[] readAll(InputStream is) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); byte[] buf = new byte[1024]; int c = is.read(buf); while (-1 != c) { baos.write(buf, 0, c); c = is.read(buf); } baos.flush(); baos.close(); return baos.toByteArray(); } }