Skip to content

Commit f4e1197

Browse files
committed
Use try-with-resource in examples
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1610781 13f79535-47bb-0310-9956-ffa450edef68
1 parent d6de806 commit f4e1197

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/site/xdoc/user-guide.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,14 @@ for (CSVRecord record : records) {
3939
class from <a href="https://commons.apache.org/proper/commons-io/">Apache Commons IO</a> for example:
4040
</p>
4141
<source>final URL url = ...;
42-
final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
43-
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
44-
try {
42+
try (
43+
final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
44+
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
45+
) {
4546
for (final CSVRecord record : parser) {
4647
final String string = record.get("SomeColumn");
4748
...
4849
}
49-
} finally {
50-
parser.close();
51-
reader.close();
5250
}</source>
5351
</section>
5452
<!-- ================================================== -->

0 commit comments

Comments
 (0)