Reading from a BufferedReader (readLine) returns null?

a 夏天 提交于 2019-12-01 07:34:23

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/10202515/reading-from-a-bufferedreader-readline-returns-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!