How do I take a ByteArrayInputStream and have its contents saved as a file on the filesystem

Ankur picture Ankur · May 13, 2010 · Viewed 36.5k times · Source

I have an image which is in the form of a ByteArrayInputStream. I want to take this and make it something that I can save to a location in my filesystem.

I've been going around in circles, could you please help me out.

Answer

Simon Nickerson picture Simon Nickerson · May 13, 2010

If you are already using Apache commons-io, you can do it with:

 IOUtils.copy(byteArrayInputStream, new FileOutputStream(outputFileName));