• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

byte[] to file

 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a byte[] that contains binary image data (for pngs and gifs). I can't figure out how to write this data to a file.
Can anyone give me an overview of what I need to do?
Thanks!
 
kishor rao
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileOutputStream f = new FileOutputStream("pic.gif");
for(int i = 0; i < <size of ur byte array>; i++)
f.write(<ur byte array name>[i]);
f.close();
i think this should do it.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need for a loop - just spit out the whole array at once:

The BufferedOutputStream is optional, but a good idea in general for efficiency.
[ January 30, 2003: Message edited by: Jim Yingst ]
 
Dave Comeau
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked perfect. Thanks so much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic