从BufferedReader(readLine)读取返回null? [英] Reading from a BufferedReader (readLine) returns null?

查看:249
本文介绍了从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();

然而,即使<$ c $,尝试打印到屏幕时结果也为null c> 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.

这篇关于从BufferedReader(readLine)读取返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆