From 3239fec94cdd7876130b87070d2d71148d9ef50b Mon Sep 17 00:00:00 2001 From: "liujisi@google.com" Date: Tue, 7 Jun 2011 03:51:33 +0000 Subject: Close resources properly for java tests and examples. --- examples/AddPerson.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/AddPerson.java b/examples/AddPerson.java index 4917684b..ca5ac273 100644 --- a/examples/AddPerson.java +++ b/examples/AddPerson.java @@ -70,8 +70,11 @@ class AddPerson { // Read the existing address book. try { FileInputStream input = new FileInputStream(args[0]); - addressBook.mergeFrom(input); - input.close(); + try { + addressBook.mergeFrom(input); + } finally { + try { input.close(); } catch (Throwable ignore) {} + } } catch (FileNotFoundException e) { System.out.println(args[0] + ": File not found. Creating a new file."); } @@ -83,7 +86,10 @@ class AddPerson { // Write the new address book back to disk. FileOutputStream output = new FileOutputStream(args[0]); - addressBook.build().writeTo(output); - output.close(); + try { + addressBook.build().writeTo(output); + } finally { + output.close(); + } } } -- cgit v1.2.3