I have a byte array representation of a Image. How to save it on disk as an image file.
I have already done this
OutputStream out = new FileOutputStream("a.jpg");
out.write(byteArray);
out.flush();
out.close();
But when I open the image by double-clicking it, it doesn’t show any image.
Other than failing to use a try/finally block (at least in the code you’ve shown) that should be fine. (You don’t need to flush an output stream if you’re closing it, by the way.)
As it’s not working, that suggests
byteArraydoesn’t actually contain a JPEG-encoded image. How have you createdbyteArrayto start with? If it’s a “raw” representation, you’ll probably want to encode it, e.g. using the javax.imageio package.