• 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

URLConnection

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all is it possible to use URLConnection to create a file, then create content in the file and save it on a server

e.g. i want to create a file myfile.txt add some text to it, e.g. "this is my text" and save myfile.txt to the server with an address like this

http://server.domain.com/FolderName/

can some one show me how i do this

i've got this far, but don't know how to create the file and add content to it

URL url = new URL(fileLocation + "/" + fileName);

URLConnection urlConnection = url.openConnection();

urlConnection.setDoOutput(true);

OutputStream outputStream = urlConnection.getOutputStream();
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can definitely do this, but only if the server cooperates; there has to be code (a servlet, for example) running on the server which knows how to accept the data and save it to a file. The details of the exchange will be, of course, up to whoever designs the server-side code.
 
dale conn
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm writing the server-side code

i'm gathering data from a database, creating a file putting the data gathered into that file then copy that file to the server

can you show me how i do that

many thanks for any help
 
dale conn
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no worries now sorted it
 
reply
    Bookmark Topic Watch Topic
  • New Topic