This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Writing a file across a network Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Writing a file across a network" Watch "Writing a file across a network" New topic

Writing a file across a network

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1114
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.
// 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

Joined: Mar 06, 2001
Posts: 13459

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.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1114
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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Writing a file across a network
It's not a secret anymore!