Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] stream2ByteArrayQuiet(InputStream inStream) { byte[] result = null; try { result = stream2ByteArray(inStream); } catch (IOException e) { // nothing to do } finally { try { inStream.close(); } catch (IOException e) { // nothing to do } finally { inStream = null; } } return result; } public static byte[] stream2ByteArray(InputStream inStream) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len = 0; byte[] buffer = new byte[1024 * 10]; while ((len = inStream.read(buffer)) != -1) { baos.write(buffer, 0, len); } byte[] result = baos.toByteArray(); baos.close(); inStream.close(); return result; } }