aspose file tools*
The moose likes Java in General and the fly likes upload and download files using java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "upload and download files using java" Watch "upload and download files using java" New topic
Author

upload and download files using java

m luu
Greenhorn

Joined: Jan 19, 2004
Posts: 2
Please let me know how to upload and download files using java. Thanks in advance.
mluu
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
To download directly from a URL:
- create a URL from the URL string
- create a URLConnection by sending openConnection to the URL
- on the connection, setUsesCaches to false, setDoInput to true, setDoOutput to false
- obtain the InputStream from the URLConnection
- copy the file using something like this:

(The IOUtil methods, part of a utility class here, simply ensure that the references aren't null before closing the streams.)
If you're looking to do this via servlets, that's a different solution.
-Jeff L.-
[ January 19, 2004: Message edited by: Jeff Langr ]

Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
mylifeisjava javaislife
Greenhorn

Joined: Jan 20, 2004
Posts: 4
I did lot of research and found that using input type=file in jsp i could serach for the file on the client system.I could not make out what do I write on the server side(i.e. in my java class).
Please help me with some code or any links.Thanks for your help.
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
Originally posted by mylifeisjava javaislife:
I did lot of research and found that using input type=file in jsp i could serach for the file on the client system.I could not make out what do I write on the server side(i.e. in my java class).
Please help me with some code or any links.Thanks for your help.

Search for "file upload servlet" on Google. There appear to be many freely available source code examples, including one from O'Reilly. It's not a terribly difficult thing to do, nor is it trivial. It involves parsing a multipart/form-data request.
Good luck,
Jeff L.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: upload and download files using java