开发者

Unable to open URL stream

开发者 https://www.devze.com 2023-04-07 01:11 出处:网络
The code below is for a Google App Engine project. Why do I get a Stream Closed error without seeing any line returned?

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

精彩评论

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

关注公众号