(original title: help a newbie (Java))
I need a java code for downloading files from the internet ..For example I want to download doc,pdf files from the internet means i have to do it through my code ..So can anyone help me
(original title: help a newbie (Java))
I need a java code for downloading files from the internet ..For example I want to download doc,pdf files from the internet means i have to do it through my code ..So can anyone help me
Make use of java.net.URLConnection
. Here's a Sun tutorial about that. It contains teh codez.
Take a look at the Apache HTTPClient project: http://hc.apache.org/httpclient-3.x/
There are tons of samples on the Samples section of the site: http://svn.apache.org/viewvc/httpcomponents/oac.hc3x/trunk/src/examples/
And the User Guide is also quite good!
Strange that you would ask this in 2010 http://www.daniweb.com/forums/thread84370.html
It's easiest if you use Apache Commons IO:
IOUtils.copy(
new URL("http://www.server.com/file.doc").openStream(),
new FileOutputStream("C:/path/to/file.doc")
);
Otherwise, you have to write a loop and use a byte array as buffer, which can be a bit tricky to get exactly right.