jQuery in Action, 3rd edition
The moose likes I/O and Streams and the fly likes write byte[] to file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "write byte[] to file?" Watch "write byte[] to file?" New topic

write byte[] to file?

Subha Rangu

Joined: Jul 23, 2004
Posts: 29
How do you write byte[] to a File of an image type.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

If you've already got the byte[], then just

would do it (import java.io.FileOutputStream, of course.)

[Jess in Action][AskingGoodQuestions]
Subha Rangu

Joined: Jul 23, 2004
Posts: 29
I could write the byte[] to a file.But I want to have that with a particular extension. Like "tif". the code I wrote:

File f=new File("c:/temp/od/test.tif");
FileOutputStream fout = new FileOutputStream(f);
fout.write(b);//b is byte[] obtained..
return f;

My question is:
Is this the right way to specify the file extension?. I could open the file from ie,paint etc. But the problem is I was not able to include it in <img> tag using HTML. I appreaciate if someone could help me out.
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

The img tag doesn't support TIF. The only reason IE opens the file is because Windows associates the TIF file extension with Kodak Imaging for Windows program. Use a PNG, JPG or GIF if you want to embed the image in HTML.

[How To Ask Questions On JavaRanch]
I agree. Here's the link: http://aspose.com/file-tools
subject: write byte[] to file?
It's not a secret anymore!