Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static byte[] readStream(InputStream in) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = -1; while ((len = in.read(buffer)) != -1) { outputStream.write(buffer, 0, len); } outputStream.close(); in.close(); return outputStream.toByteArray(); } }