从BufferedReader(readLine)读取返回null?
问题描述:
我目前正在尝试从 BufferedReader
中读取 String
,但无法找到方法来执行此操作。 。
I am currently trying to read a String
from a BufferedReader
but cant find a way to do this...
当然我试过
BufferedReader inStream = null;
inStream = new BufferedReader(new InputStreamReader(client.getInputStream()));
String test = inStream.readLine();
然而,即使 BufferedReader inStream 等于某种消息。
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.
答
基于文档, BufferedReader.readLine()
仅在到达流的末尾时返回 null
。这意味着如果第一次调用 readLine()
返回 null
,则输入流中没有任何内容可以开始。
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.