java - Dealing with end of 'file' using BufferedReader.read() -


I have a client server program that should send the contents of the file as a string and The problem is that how to eliminate the loop in which the BufferedReader.read method is the I code:

  while ((c = in.read ())! = -1) {fw .write ((four) c); System.out.print ((four) c); }   

But since it uses sockets, it never reaches 1 until the socket closes. Unless I can not find an end segment to reach the loop, are there any special characters?

went with:

  while ((line = in.readline ())! = Null & amp;; line.equals (BasicProtocol.SENDING_FILE_DONE)) < / Code>  

where SENDING_FILE_DONE is a string that has been added at the end of the stream. There is not a good way to do this, but in this manner (I believe) when the data string should be.

I have a client server program, which is the content of a file as a string

Why? Bad idea It should be sent as a byte. Otherwise you are running the risk of data corruption. There is a problem deciding to end the loop with

and BufferedReader.read () method . I

  1. You should not use BufferedReader , to avoid the notion that you should use the BufferedInputStream to join the file.
  2. You should have sent a file size in front of the file, and you should read the file size, then the loop should be read as long as you do not read too many bytes properly, or you have to send the file The latter socket should be closed.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -