read InputStream and return byte array - Android File Input Output

Android examples for File Input Output:InputStream

Description

read InputStream and return byte array

Demo Code


//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

public class Main {

    public static byte[] readStream(InputStream inStream) throws Exception {
        byte[] buffer = new byte[1024];
        int len = -1;
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        while ((len = inStream.read(buffer)) != -1) {
            outStream.write(buffer, 0, len);
        }/*from   ww  w  .j  av a2s. c o  m*/
        byte[] data = outStream.toByteArray();
        outStream.close();
        inStream.close();
        return data;

    }
}

Related Tutorials