Re: Save gif file from the URL



Thomas Fritsch schrieb:
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; /**/)
Sorry for the bug. I meant:
for (int c = input.read(); c != -1; c = input.read())
output.write(c);
input.close();
output.close();

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



--
Thomas
.