This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "byte[] to file" Watch "byte[] to file" New topic

byte[] to file

Dave Comeau

Joined: Jun 14, 2002
Posts: 27
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?
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]);
i think this should do it.
Jim Yingst

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

Joined: Jun 14, 2002
Posts: 27
Worked perfect. Thanks so much!
wood burning stoves
subject: byte[] to file
Similar Threads
Convert image to byte[] and viceversa
uploading files, using more than one element in the form
Lots of .nfs files being created
java.util.Vector --> byte[] ?
Unicode with byte streams?