Jonas Arcangel
Jonas Arcangel

Reputation: 1925

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 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");

Upvotes: 1

Views: 299

Answers (2)

systempuntoout
systempuntoout

Reputation: 74074

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

Upvotes: 1

Andrew Briggs
Andrew Briggs

Reputation: 1349

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

or no try this

URLConnection urlc=url.openConnection();

Upvotes: 0

Related Questions