• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Storing images in a file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello,

I am writing a program that receives an image from a server and stores the bytes of this images in a buffered stream. How can I then store this image in a file in a specific directory?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

nadia mcday wrote:
How can I then store this image in a file in a specific directory?



Are you comfortable with Java IO ?

Have you looked at Image IO API from SUN.
 
nadia mcday
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am not too comfortable with IO, to tell the truth! I looked at the image IO class, it seems to be what I need, but if I have a stream of bytes how can I convert it to a buffered image? In fact what I am doing is reading the data from a socket. Is there a way to read the a buffered image directly from the socket?
Thanks a lot!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have the raw bytes to work with, then creating a BufferedImage first, just so that you can then use ImageIO, is probably not the best route.

The java.io.File, java.io.FileOutputStream, and (optionally) java.io.BufferedOutputStream classes should be all you need.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sagar Rohankar wrote:

nadia mcday wrote:
How can I then store this image in a file in a specific directory?



Are you comfortable with Java IO ?

Have you looked at Image IO API from SUN.


To expand what Ulf mentioned: the Java IO API is not to be confused with the Java 2D API. Those are completely unrelated to each other.

The Java IO API is documented here: http://java.sun.com/javase/6/docs/api/java/io/package-summary.html
There is a tutorial as well: http://java.sun.com/docs/books/tutorial/essential/io/
 
Crusading Chameleon likes the size of this ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic