Get an image from a website

I cant figure out how to get an image off of a website, is their a class that can do this?...if so could some one kindly point me to the docs of said class

[162 byte] By [The_Undeada] at [2007-11-27 11:28:49]
# 1

BufferedImage im = ImageIO.read(url);

http://java.sun.com/javase/6/docs/api/javax/imageio/ImageIO.html

BigDaddyLoveHandlesa at 2007-7-29 16:24:18 > top of Java-index,Java Essentials,New To Java...
# 2

Image file should have its URL. You can open and read the URLConnection on that.

Ah, yes, BDLH's code is much more simple.

Message was edited by:

hiwa

hiwaa at 2007-7-29 16:24:18 > top of Java-index,Java Essentials,New To Java...
# 3

import java.net.*;

import java.io.*;

import java.util.Scanner;

class ImageGrabber {

public static void main(String[] argv) throws Exception {

FileOutputStream fos;

Socket s;

String pathToImage;

String file;

InputStream is;

Scanner kbd = new Scanner(System.in);

URLConnection connection;

URL url;

int in;

System.out.print("Enter URL of picture: ");

pathToImage = kbd.nextLine();

System.out.print("File to save to: ");

file = kbd.nextLine();

connection = new URL(pathToImage).openConnection();

connection.connect();

is = connection.getInputStream();

fos = new FileOutputStream(file);

while( (in = is.read()) != -1 ) {

fos.write(in);

}

System.out.println("Done.");

fos.close();

is.close();

}

}

Navy_Codera at 2007-7-29 16:24:18 > top of Java-index,Java Essentials,New To Java...
# 4

... I prefer the LONG way ...

Navy_Codera at 2007-7-29 16:24:18 > top of Java-index,Java Essentials,New To Java...
# 5

Thanx guys, i will try both solutions

The_Undeada at 2007-7-29 16:24:18 > top of Java-index,Java Essentials,New To Java...
# 6

> ... I prefer the LONG way ...

I guess it all comes down to how you define "how to get an image".

OP: you are being too vague! What are you trying to do? Be clear!

BigDaddyLoveHandlesa at 2007-7-29 16:24:18 > top of Java-index,Java Essentials,New To Java...