()
| 5 | public class FinallyTest { |
| 6 | |
| 7 | public void finallyTest() { |
| 8 | |
| 9 | InputStream in = null; |
| 10 | |
| 11 | try { |
| 12 | in = new FileInputStream("foo.txt"); |
| 13 | byte head[] = new byte[8]; |
| 14 | if (in.read(head) == 8) { |
| 15 | System.out.println(head); |
| 16 | } |
| 17 | } catch (IOException e) { |
| 18 | e.printStackTrace(); |
| 19 | } |
| 20 | // although bad form it is legal |
| 21 | finally { |
| 22 | try { |
| 23 | if (in != null) { |
| 24 | in.close(); |
| 25 | } |
| 26 | } catch (IOException e2) { |
| 27 | e2.printStackTrace(); |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | } |