This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
praveen kumar gowda wrote:i have doubt in two conditon....wheather the statment get executed
I assume you meant to say statement(s) after finally block.
Well, programmatically, only thing which can stop finally block from execution is - if try and/or catch block contains a call to system.exit and that call is getting executed (e.g. if catch contains system.exit, but there's not exception, then finally block will be executed). There are non-programmatic things which can prevent finally block from getting executed - like JVM crash, OS crash, catastrophic failure, non-maskable interrupt (say power supply is disconnected) etc.
Now, about statement(s) after finally block:
1) If exception(s) occur in finally block, and those exceptions are handled, and no new exceptions are thrown from catch block, then those statements(statements after finally block) get executed.
2) If exception(s) occur before finally block, and those exceptions are handled, and no new exceptions are thrown from catch block, then those statements(statements after finally block) get executed.
In your code, you are not catching any exception in first catch block. So, if any exception occurs there, statements after finally block will not be executed.
In your finally block, you are handling only IOException. So, if any other exception occurs, then statements after finally block will not be executed.
By the way (its not related to your question, but) if your openFile says that it throws IOException, then inside instead of doing something clever, you can simply
I hope this helps.
Please use code tags; you can go back and edit your post, which is difficult to read without them.
Why on earth are you using the read() method. Why are you not buffering your input? Look at this post of Rob Spoor’s, which shows how to do it. You can alter that code to insert something after the finally, and inside the outer try , and see what happens.