Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static byte[] readInputStream(InputStream is) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); final int blockSize = 8192; byte[] buffer = new byte[blockSize]; int count = 0; try { while ((count = is.read(buffer, 0, blockSize)) > 0) { byteStream.write(buffer, 0, count); } return byteStream.toByteArray(); } catch (Exception e) { return null; } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } } } }