This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

write byte[] to file?

 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you write byte[] to a File of an image type.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you've already got the byte[], then just



would do it (import java.io.FileOutputStream, of course.)
 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic