How to convert inputstream to byte array in android and java


public byte[] convertInputStreamToByteArray(InputStream inputStream)
 {
 byte[] bytes= null;

 try
 {
 ByteArrayOutputStream bos = new ByteArrayOutputStream();

 byte data[] = new byte[1024];
 int count;

 while ((count = inputStream.read(data)) != -1)
 {
 bos.write(data, 0, count);
 }

bos.flush();
 bos.close();
 inputStream.close();

bytes = bos.toByteArray();
 }
 catch (IOException e)
 {
 e.printStackTrace();
 }
 return bytes;
 }
Advertisements

About krishjlk

http://www.facebook.com/krishna.kanth.121

One response to “How to convert inputstream to byte array in android and java”

  1. java2novice says :

    very nice. for more java examples visit java2novice.com site

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: