0

Possible Duplicate:
How do you Programmatically Download a Webpage in Java

How to download a file using java. So for example, I want to construct a program which will take some input e.g the website download. and then download the file. Please note that I am not looking for the code or anything. I just want to be pointed in the correct direction and that's it.

Community
  • 1
  • 1
Jeel Shah
  • 3,274
  • 17
  • 47
  • 68
  • how is this a duplicate, can you not read? I want to download a file not a webpage.... read the question then comment if it is a duplicate or not. – Jeel Shah May 23 '11 at 14:02
  • 2
    I can read. Downloading a file and a webpage over the internet is the exact same process. Technically speaking, a webpage is a file. – jjnguy May 23 '11 at 14:03
  • @jjnguy i want to download a file e.g .pdf .xls etc when i was writing that i was not using techincally terms but terms where your not supposed to technical. – Jeel Shah May 23 '11 at 14:08
  • 1
    your accepted answer is using the same process as the question I linked to. You can download pdfs and excel files over http just the same as you would download html files. – jjnguy May 23 '11 at 14:15

4 Answers4

4

If you want to download a file from a URL, have a look at java.net.URLConnection.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
3

Have a look at this Stack Overflow question:

How do you Programmatically Download a Webpage in Java

Community
  • 1
  • 1
jjnguy
  • 136,852
  • 53
  • 295
  • 323
2

By using HttpURLConnection (better than java.net.URLConnection IMHO)

Manuel Salvadores
  • 16,287
  • 5
  • 37
  • 56
2

URLConnection.getInputStream() is what you're looking for. Moving the actual bytes is a bit tedious and error-prone, so if you just want to get it done, using an existing, tested implementation like FileUtils from Apache commons IO would be the best idea.

Michael Borgwardt
  • 342,105
  • 78
  • 482
  • 720