Skip to content Skip to sidebar Skip to footer

Is There An Alternative To FileOutputStream Type , Which Does Not Create A File?

To process some images in my android application I currently use code like this: FileOutputStream fileOuputStream = new FileOutputStream(imgpath); [..DO SOME STUFF..] Bitm

Solution 1:

If you are able to use an InputStream or OutputStream you can use ByteArrayInputStream or ByteArrayOutputStream for in memory handling of the data.

If you have two thread you can also use PipedInputStream and PipedOutputStream together to communicate between the threads.


Solution 2:

You could write your data to a ByteArrayOutputStream and use the byte array of that stream:

ByteArrayOutputStream out = new ByteArrayOutputStream();
data.compress(Bitmap.CompressFormat.JPEG, 90, out); 

// now take the bytes out of your Stream
byte[] imgData = out.toByteArray();

Post a Comment for "Is There An Alternative To FileOutputStream Type , Which Does Not Create A File?"