Charlie
Charlie

Reputation: 1338

Reading from a BufferedReader (readLine) returns null?

I am currently trying to read a String from a BufferedReader but cant find a way to do this...

Of course I tried

BufferedReader inStream = null;
inStream = new BufferedReader(new InputStreamReader(client.getInputStream()));
String test = inStream.readLine();

However the result turns out as null when trying to print to a screen even though the BufferedReader inStream is equal to some kind of message.

Upvotes: 3

Views: 14548

Answers (1)

Attila
Attila

Reputation: 28762

Based on the documentation, the BufferedReader.readLine() returns null only when the end of the stream is reached. This means if the first call to readLine() returns null, there was nothing in the input stream to begin with.

Upvotes: 11

Related Questions