Here you can find the source of InputStram2byteArray(InputStream in)
public static byte[] InputStram2byteArray(InputStream in)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static byte[] InputStram2byteArray(InputStream in) { try {//from ww w . j av a 2 s.co m 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; } }