This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "write byte[] to file?" Watch "write byte[] to file?" New topic
Author

write byte[] to file?

Subha Rangu
Greenhorn

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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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



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


[Jess in Action][AskingGoodQuestions]
Subha Rangu
Greenhorn

Joined: Jul 23, 2004
Posts: 29
Hi,
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..
fout.close();
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.
Thanks
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: write byte[] to file?
 
Similar Threads
File Object
byte array to bits
howto stream mp3
sending pdf files to IBM MQ
java.nio.ByteBuffer?