【问题标题】:All possible reasons for readline() to be nullreadline() 为空的所有可能原因
【发布时间】:2014-03-05 06:12:14
【问题描述】:

代码片段:

    HttpURLConnection url = new HttpURLConnection(new URL("myurl"));
    InputStream connInputStream = null;
    try 
           {
              connInputStream = conn.getInputStream();
               BufferedReader in = new BufferedReader(new     InputStreamReader(connInputStream));
               boolean matchFound = false;
               String strLine = in.readLine();
    }
...

在这段代码中,我得到 strLine = null,这意味着 in.readLine 为 null。 in.readline 可能为空的可能原因是什么。 这段代码不会抛出任何空指针异常。

这种情况会不会因为读取 url 源到流的时间滞后而出现?

【问题讨论】:

标签: java url


【解决方案1】:

只有一个原因:you've reached the end of the underlying stream。流的结束取决于底层流的实现。

【讨论】:

    猜你喜欢
    • 2011-09-29
    • 2019-06-27
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 1970-01-01
    相关资源
    最近更新 更多