The problem
The problem is that you execute the br.close()
that, as javadoc states, closes the stream and releases any system resources associated with it.
Just for a quick verification comment out the:
if (br != null) {
// try {
// br.close();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
and you can answer s
any times you want without any exception.
A solution
A solution is closing the buffer reader after all reads are terminated:
String moreSearch = null;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try {
do {
// ...
System.out.println("More Flight Query ? Press n/N to exit. Anyother key to continue searching.");
moreSearch = br.readLine();
} while (!moreSearch.equalsIgnoreCase("n"));
} catch (IOException e) {
Logger.getLogger(FlightSearch.class.getName()).log(Level.SEVERE, "Cant read line from a System.in based BufferedReader", e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ignoreMe) {
Logger.getLogger(FlightSearch.class.getName()).log(Level.SEVERE, "Can't close a System.in based BufferedReader", ignoreMe);
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…