Wraps locals variable of the AutoCloseable type in a try-with-resources statement.