2

I am supposed to implement a simple Client/Server application similar to FTP Server/Client .

Both the client and the server should be able to send and receive files, but for now let's address just sending a file from the server to the client.

There is already an open socket between them, I do not wish to use a byte buffer. I tried the Files.copy() method, it created a file at the client side but it was filled with rubbish.

I have been trying to use FileChannel.transferFrom/To but I can't seem to get it right.

could someone provide an example of how to use it over a socket ?

Maverick
  • 62
  • 1
  • 9
  • Well, open a `SocketChannel` to the other end, then use `.transferTo()`; what parts don't you get about this? Also, what code have you tried so far? – fge Nov 08 '14 at 19:21
  • I'm sort of new to java, how is the SocketChannel different ? Can you include a link or a simple example ? – Maverick Nov 08 '14 at 19:28
  • 1
    I'd rather not; not unless you edit your question to show your current code. From your text it seems you have managed to obtain a `Channel` from the file source but are not able to obtain one for a socket. Without a code base, code samples hurdled at you may only end up confusing you. So, code, please! – fge Nov 08 '14 at 19:30

0 Answers0