File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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<!-- ================================================== -->
You can’t perform that action at this time.
0 commit comments