1 URL url = new URL("http://www.yahoo.com/image_to_read.jpg");
2InputStream in = new BufferedInputStream(url.openStream());
3ByteArrayOutputStream out = new ByteArrayOutputStream();
4byte[] buf = new byte[1024];
5int n = 0;
6while (-1!=(n=in.read(buf)))
7{
8 out.write(buf, 0, n);
9}
10out.close();
11in.close();
12byte[] response = out.toByteArray();
13
1(throws IOException)
2
3Image image = null;
4try {
5 URL url = new URL("http://www.yahoo.com/image_to_read.jpg");
6 image = ImageIO.read(url);
7} catch (IOException e) {
8}
9
1URL url = new URL("http://upload.wikimedia.org/wikipedia/commons/9/9c/Image-Porkeri_001.jpg");
2InputStream in = new BufferedInputStream(url.openStream());
3OutputStream out = new BufferedOutputStream(new FileOutputStream("Image-Porkeri_001.jpg"));
4
5for ( int i; (i = in.read()) != -1; ) {
6 out.write(i);
7}
8in.close();
9out.close();
10