Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static byte[] InputStram2byteArray(InputStream in) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (in != null) { byte[] buffer = new byte[1024]; int length = 0; while ((length = in.read(buffer)) != -1) { out.write(buffer, 0, length); } out.close(); in.close(); return out.toByteArray(); } } catch (Exception e) { e.printStackTrace(); } return null; } }