Alex Rivera | Logout

Create a file from a ByteArrayOutputStream

Asked 2013-07-05T12:06:34.193
98

Can someone explain how I can get a file object if I have only a ByteArrayOutputStream. How to create a file from a ByteArrayOutputStream?

Edit
Report

1 Answer

177

You can do it with using a FileOutputStream and the writeTo method.

ByteArrayOutputStream byteArrayOutputStream = getByteStreamMethod();
try(OutputStream outputStream = new FileOutputStream("thefilename")) {
    byteArrayOutputStream.writeTo(outputStream);
}

Source: "Creating a file from ByteArrayOutputStream in Java." on Code Inventions

answered 2013-07-05T12:08:00.280

Your Answer