Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Writing a file across a network

 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you write a file across a socket connection you create when communicating between a network client and the server?
I'm tempted to believe that you can do something like this:
// on server
File f = new File("Test.txt")
if (f.exists())
// output is an ObjectOutputStream.
output.writeObject(f);
===========================================
// Then, client processes received object as a file.
Is this how to best do it or do I need to actually
break down the file and send it byte by byte?
Thanks for anyone's input.
-- Mike
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, not the way to do it.
You need to use the File class to get a reference to the file, open an InputStream or Reader to get the datat from the file, then write this data to the OutputStream.
Dave
 
Mike London
Ranch Hand
Posts: 1290
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David,
I figured the way I was doing it wasn't going to work.
I'll look for some examples. <s>
Thanks again.
-- Mike
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!