Re: Save gif file from the URL



mark wrote:
I just want to save on disc a gif file taken from the internet (i.e.
save as logo.gif the image
http://www.google.com/intl/us_ALL/images/logo.gif ). Is it possible
without much effort (I have read about the extra & not free libraries
but I hope there is a simple way to do so (just read bytes and write
bytes - no modification).

In principle it is very easy:

URL url = new URL("http://www.google.com/intl/us_ALL/images/logo.gif";);
InputStream input = url.openStream();
OutputStream output = new FileOutputStream("logo.gif");
for (int c = input.read(); c != -1; /**/)
output.write(c);
input.close();
output.close();

Try/catch for IOExceptions and performance-optimizing is left to the reader
as an exercise. ;-)

--
"Thomas:Fritsch$ops.de".replace(':', '.').replace('$', '@')
.



Relevant Pages

  • Re: Save gif file from the URL
    ... Thomas Fritsch schrieb: ... without much effort (I have read about the extra & not free libraries ... URL url = new URL; ... as an exercise. ...
    (comp.lang.java.help)
  • watershed & region growing
    ... I need some free libraries to do watershed and regiongrowing with some ... Can you give me a hint please. ...
    (comp.lang.java.gui)