File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting images from web

 
Goat Boy
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I want my program to get number of images from the web
http://www.url.com/img01.jpg
.
.
.
http://www.url.com/img99.jpg
What should I use in order to read images and save it to my hard drive?
URL url = new URL("http://www.url.com/img01.jpg");
InputStream is = urlConnection.getInputStream();
something like that?
but it does not work and I don't know how to "convert" inputstream to file....
Please help!
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possiblity is to also create an OutputStream that writes to a file. You can then read the data from the InputStream you created from the URL and write it to this OutputStream.

HTH

Layne
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are some example snippets. We usually don't like giving away too much of the solution, but these IO thingies are hard to assemble by just reading the docs ...

You could surely be more efficient by reading and writing arrays of bytes, but I have some other code in between read & write to check for various conditions. I leave it to you to detect EOF.

BTW: Change your user name before the law comes around. It should be a believable first & last name, tho not necessarily your real name. Mine isn't.
[ July 09, 2005: Message edited by: Stan James ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic