I have a while loop that goes while a BuffedReader still has data, what the while loop is meant to be doing is reading each line and then continuing on. This is what I have
final BufferedReader in;
....
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line = null
while ((line = in.readLine()) != null) {
line = line.replace(" ", ",");
reply.append(line + System.getProperty("line.separator"));
Log.d("DeviceActivity", line);
}
- Edit
This reads the two lines that are expected and then it doesn’t finish the loop like it is meant to.
I have tried it with different inputs as well but same result, it doesn’t exit the while loop.
Does anyone know how to prevent this?
Also its not always two lines, it could be infinite.
This here works, it will only read the line if the input stream is ready.