341
9-6. Managing Resources with try/catch Blocks
Problem
In the event of an exception, you need to ensure that any resources used within a
try/catch block are released.
Solution
Use the Automatic Resource Management (ARM) feature, which can be specified with
a try-with-resources statement.
When using that statement, any resources specified
within the try clause are automatically released when the block terminates. In the
following code,
the FileOutputStream, BufferedOutputStream, and DataOutputStream
resources are automatically handled by the try-with-resources block.
Do'stlaringiz bilan baham: