开发者

Unable to open URL stream

The code below is for a Google App Engine project.

Why do I get a Stream Closed error without seeing any line returned?

I am 开发者_StackOverflow社区definite that the page the URL points to is active.

URL url = new URL("http://banico.com.au");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line;

resp.getWriter().println("START");

while ((line = reader.readLine()) != null) 
{
    reader.close();
}

resp.getWriter().println("END");


You should move the reader.close(); outside of the while statement.


I think you have to wrap the BufferedReader instantiation inside a try catch block

or no try this

URLConnection urlc=url.openConnection();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜