I have the following method for reading a web page:
public String readURL() {
String response="";
try {
URL url=new URL(urlString);
BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream()));
response=br.readLine();
br.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"Unable to connect to server: "+e.toString(),windowTitle,JOptionPane.ERROR_MESSAGE);
System.exit(-1);
}
return(response);
}
When I call this method the first time, it always works. However, when I call it a second time (within the same run) the InputStreamReader times out. The urlString is the same both times. I can rerun the application and the first call succeeds. I can use that urlString as many times in a row as I want from a browser and it always succeeds. It seems like there is something that I am not closing or some kind of clean up I need to do. What is the method missing in order to do subsequent calls? TIA.