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();
精彩评论