File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Client Server File transfer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Client Server File transfer" Watch "Client Server File transfer" New topic

Client Server File transfer

Adrian Lee
Ranch Hand

Joined: May 10, 2007
Posts: 71
Hi everyone. I'm building a client-server file transfer project. I was told to use DataOutputStream and DataInputStream.

I've some codes that I've found from a Java cookbook which is able to open a connection port to send a message to the server. I've managed to get the client and server to communicate.

However, I'm kinda lost on how can I get it to transfer a file. Can any kind soul guide me on how I can acheive that?

Many thanks~!!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I think it's as easy as read bytes from disk on one end, send bytes over the wire, write bytes to disk on the other end. You can make up a protocol, say send a header first with the filename and length, followed by length number of bytes. The Sun Networking Tutorial has some neat examples of the "knock knock" protocol that should be good inspiration.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Adrian Lee
Ranch Hand

Joined: May 10, 2007
Posts: 71
Thanks James. Will look into that.
I agree. Here's the link:
subject: Client Server File transfer
It's not a secret anymore!