0

I have a program that

  1. Accepts an encoded base64 string
  2. Converts it to a byte array.

It does this fine.

The final step involves writing this byte array to a file. For example C:\example.jpg. I know simply writing the bytes won't work so was not sure what I would need to do to take the byte array and create a jpg with the picture that is coming in.

I have to actually send the picture as an attachment in email, but for testing purposes wanted to see if I can see a file saved and when I open up the jpg opens up. Thanks.

Bill Lee
  • 121
  • 2
  • 4
  • 8

1 Answers1

1

I'm guessing you're in need of something like this?

BufferedImage image = ImageIO.read( new ByteArrayInputStream( byteArray ) );
ImageIO.write(image, "BMP", new File("filename.bmp"));

Check out this question and answer, that's where I acquired it from: How to create a BMP file from raw byte[] in Java

Community
  • 1
  • 1
DeusExMachina25
  • 597
  • 6
  • 12
  • BufferedImage img = ImageIO.read(new ByteArrayInputStream(image)); File outputfile = new File("saved.jpg"); ImageIO.write(img, "jpg", outputfile); I had the following but file is empty. – Bill Lee Aug 12 '11 at 03:15