Search code examples
javafile-iobytearrayinputstream

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


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.


Solution

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

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