This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Copying Files over a Socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Reply locked New topic

Copying Files over a Socket

J Mangual

Joined: Nov 15, 2008
Posts: 16
I want to copy files over a network reliably. The program I have works except for two things:
  • The socket connection should terminate after receiving the file. In runtime, the connection does not terminate. My guess is, the client is stuck in the for loop that reads the file from the network.
  • When I used a test file, numbering the lines from 1 to 1000 (each lines reads "[number] ----- L" ), I noticed about 60 extra lines at the end of the file. Probably this is because I read into and copy from 1024-byte arrays which don't totally get written over at the end of the file.

  • So, how do I detect the end of file when I am using byte arrays like this? Or is there an even bigger issue.

    Joe Ess

    Joined: Oct 29, 2001
    Posts: 8834

    Please do not post the same topic more than once.

    "blabbing like a narcissistic fool with a superiority complex" ~ N.A.
    [How To Ask Questions On JavaRanch]
    I agree. Here's the link:
    subject: Copying Files over a Socket
    Similar Threads
    Copying Files over a Socket
    Copying Multiple Files Over A Socket
    Sending a file over socket
    Socket connection program works for localhost but not for other ip
    How to Change the File Name for Each Uploaded Files to the Socket Server?