I have a server-client program set that I'm working on and right now I'm having problems with the protocol because the new line at the end of the println statement is confusing the metadata.
In other words, I need to print to a PrintWriter without the new line at the end. I tried just print, but for some reason the other program doesn't get the message that way. I tried, for the sake of experimentation, adding "\n", "\r", and "\n\r" to the end of the statement and it still didn't get any data. Obviously print can't just be print+"\n\r" otherwise I would have gotten the same results using both methods; alas, only one works.
I checked the Javadocs and it says println is, "Prints a String and then terminates the line."
Does anyone know what the difference between these two methods is that might cause such drastically different behavior?
From the Javadoc for
PrintWriter
:If you're using
.print()
you have to manually.flush()
. Simply having\n
or\r\n
in yourString
does not do so which is what is causing the different behavior you see.