File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Features new in Java 7 and the fly likes try-with-resources Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "try-with-resources" Watch "try-with-resources" New topic


Rick Goff
Ranch Hand

Joined: Nov 14, 2006
Posts: 54

What are the best practices emerging for implementation/refactoring related to try-with-resources?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45364
If you have something predating try-with-resources, you should be instantiating the IfItAintBrokeDontFixIt class
Richard Reese
Ranch Hand

Joined: Jul 13, 2011
Posts: 84

I concur with Ritchie's answer. However, for the applications that uses try block and are in need of re-writing the try-with-resources block is the way to go. NetBeans 7.1.1 apparently has a tool that will assist in the conversion of an older application to Java 7, including try-with-resources conversion. I haven't used it but it is discussed at

Richard Reese
Java 8 New Features: A Practical Heads-Up Guide
I agree. Here's the link:
subject: try-with-resources
It's not a secret anymore!