• Post Reply Bookmark Topic Watch Topic
  • New Topic

URLConnection  RSS feed

 
dale conn
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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();
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
no worries now sorted it
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!