• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

upload and download files using java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please let me know how to upload and download files using java. Thanks in advance.
mluu
 
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic