views:

117

answers:

4

(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

+4  A: 

Make use of java.net.URLConnection. Here's a Sun tutorial about that. It contains teh codez.

BalusC
A: 

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!

Kico Lobo
Apache HTTPClient is an excellent, powerful library. But I think it would be intimidating for a newbie to use. I think Balus had a good idea in suggesting the simpler API complete with a gentle tutorial.
Carl Smotricz
Totally agree! :)
Kico Lobo
+1  A: 

Strange that you would ask this in 2010 http://www.daniweb.com/forums/thread84370.html

Amit Kumar
??? That is... bizarre.
Michael Borgwardt
Must be a troll copying crap from the web.
Skilldrick
Or someone who doesn't know how to formulate a smart question in English and unfortunately copied the wrongly formulated one from the internets which he found during searching for the answer. By the way, if this was been posted as a **comment** on the question, I'd upvoted it, but not this. Please don't post comments as answers.
BalusC
+4  A: 

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.

Michael Borgwardt