Convert Input Stream To Byte array - Android File Input Output

Android examples for File Input Output:Byte Array Convert

Description

Convert Input Stream To Byte array

Demo Code


//package com.java2s;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    private static byte[] InputStreamToByte(InputStream is)
            throws IOException {
        ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
        int ch;/*from  ww  w  . j a  v a2s  .  c  o m*/
        while ((ch = is.read()) != -1) {
            bytestream.write(ch);
        }
        byte imgdata[] = bytestream.toByteArray();
        bytestream.close();
        return imgdata;
    }
}

Related Tutorials