I have a client server program which MUST send a file's content as a String and am having trouble deciding how to end the while loop containing the BufferedReader.read method.I have the code as:
while((c = in.read()) != -1){
fw.write((char)c);
System.out.print((char)c);
}
But as it uses sockets, it never reaches -1 until the socket is closed. I cant figure out an ending clause for the while loop to reach. Are there any special characters?
Went with:
while((line = in.readLine()) != null && !line.equals(BasicProtocol.SENDING_FILE_DONE))
where SENDING_FILE_DONE is a String which is added to the end of the stream. Not a good way of doing it but has to be this way (I believe) when the data must be a String.