Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { private static byte[] getBytes(InputStream is) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = new byte[2048]; int len = 0; try { while ((len = is.read(b, 0, 2048)) != -1) { baos.write(b, 0, len); baos.flush(); } } catch (IOException e) { e.printStackTrace(); } byte[] bytes = baos.toByteArray(); return bytes; } }