| 8 | public class InputFile { |
| 9 | private BufferedReader in; |
| 10 | public InputFile(String fname) throws Exception { |
| 11 | try { |
| 12 | in = new BufferedReader(new FileReader(fname)); |
| 13 | // Other code that might throw exceptions |
| 14 | } catch(FileNotFoundException e) { |
| 15 | System.out.println("Could not open " + fname); |
| 16 | // Wasn't open, so don't close it |
| 17 | throw e; |
| 18 | } catch(Exception e) { |
| 19 | // All other exceptions must close it |
| 20 | try { |
| 21 | in.close(); |
| 22 | } catch(IOException e2) { |
| 23 | System.out.println("in.close() unsuccessful"); |
| 24 | } |
| 25 | throw e; // Rethrow |
| 26 | } finally { |
| 27 | // Don't close it here!!! |
| 28 | } |
| 29 | } |
| 30 | public String getLine() { |
| 31 | String s; |
| 32 | try { |