*
The moose likes Beginning Java and the fly likes byte[] to file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "byte[] to file" Watch "byte[] to file" New topic
Author

byte[] to file

Dave Comeau
Greenhorn

Joined: Jun 14, 2002
Posts: 27
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

Joined: Dec 10, 2002
Posts: 35
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

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
Dave Comeau
Greenhorn

Joined: Jun 14, 2002
Posts: 27
Worked perfect. Thanks so much!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: byte[] to file