Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

downloading images

Status
Not open for further replies.
Oct 15, 2003
145
US
I'm trying to figure out the best way to download images from my server onto a client's machine. There are three options I have found that may work, but I need to understand how each of these work specifically.

FileInputStream
FileReader
FileChannel

Does anyone have any suggestions on where to look to find information on each of these and specifics on how they work? Or does anyone know that can tell me?

I've looked on Sun's site and the stuff there just doesn't give me enough detail that I can really understand it.
 
download images from my server
What kind of server? ftp? webserver? Or isn't there a server running on your server?

Basically, you'll want to use a URL or Socket object, from there get a stream....

Let's say you have a Http server, in that case you could do:
Code:
Image img;
try
{
  URL url = new URL("[URL unfurl="true"]http://127.0.0.1/image.jpg");[/URL]
  ImageStream is = 
  ImageIO.createImageInputStream(url.openStream());
  img = ImageIO.read(is);
}catch(MalformedURLException e){
  //error stuff here
}catch(IOException e){
  //error stuff here
}
I know there is a shorter way... so here it is:
Code:
Image img;
String host = "[URL unfurl="true"]http://127.0.0.1/img.jpg";[/URL] //change this to your sever IP and image name 
try{
  img = ImageIO.read(host);
}catch [red]... you know the drill here ...[/red]

If it's not on a web server you need to create a ServerSocket on the server, wait for a connection to create a Socket on the port. Once you get one, send the image.

On the other side, you open a connection to the server using a Socket, get a ImageInputStream from the Socket and grab the image from the ImageInputStream as above in the first peice of code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top