Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] getByteArray(InputStream inputstream) { try { ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(); byte abyte1[] = new byte[1024]; do { int i = inputstream.read(abyte1); if (i == -1) break; bytearrayoutputstream.write(abyte1, 0, i); } while (true); byte result[] = bytearrayoutputstream.toByteArray(); bytearrayoutputstream.close(); inputstream.close(); return result; } catch (IOException e) { return null; } } }