Tech Me More

To quench our thirst of sharing knowledge about our day to day experience & solution to techincal problems we face in our projects.

Advertise with us !
Send us an email at diehardtechy@gmail.com

Wednesday, February 12, 2014

Java 1.7 Update: Try-With-Resources

Since JDK 1.7, a new "try-with-resources" approach is introduced. When a try block is end, it will close or release your opened file automatically.

Following is the example of the updated try block 

try(open file or resource here){

//...

}
//after try block, file will close automatically.

Example:



In JDK7, finally is no longer required. The file will be closed automatically after try block.

No comments: