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