最近 Java 7 build 105版本加入一個 Automatic Resource Management 特性,基本上,就是try-with-resources觀念。try block中所使用的resource將會自動被關閉不管正常執行完或發生錯誤,日後不需要再手動關掉resource物件,。
FEATURE SUMMARY: A *resource* is as an object that must be closed manually, such as a java.io.InputStream, OutputStream, Reader, Writer, Formatter; java.nio.Channel;java.net.socket; java.sql.Connection, Statement, ResultSet, or java.awt.Graphics. The *automatic resource management statement* is a form of the try statement that declares one or more resources. The scope of these resource declarations is limited to the statement. When the statement completes, whether normally or abruptly, all of its resources are closed automatically.