View Single Post
  #3 (permalink)  
Old 11-06-2007, 09:22 PM
javaplus javaplus is offline
Member
 
Join Date: Nov 2007
Posts: 97
javaplus is on a distinguished road
Thanks. So the example you gave, can have br.close() in finally block.

Code:
try { URL url = new URL(some_path); File file = new File(url.toURI()); BufferedReader br = new BufferedReader( new InputStreamReader( new FileInputStream(file))); // read and process file } catch(MalformedURLException mue) { System.out.println("Bad URL: " + mue.getMessage()); } catch(FileNotFoundException fnfe) { System.out.println("FileNotFound: " + fnfe.getMessage()); } catch(IOException ioe) { System.out.println("Read error: " + ioe.getMessage()); } finally{ br.close(); }
And what I know is, the finally block will execute even if no exception is caught. Is this right?
Reply With Quote