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
This commit is contained in:
parent
d6de8062b5
commit
f4e1197bdc
|
@ -39,16 +39,14 @@ for (CSVRecord record : records) {
|
|||
class from <a href="https://commons.apache.org/proper/commons-io/">Apache Commons IO</a> for example:
|
||||
</p>
|
||||
<source>final URL url = ...;
|
||||
final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
|
||||
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
|
||||
try {
|
||||
try (
|
||||
final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
|
||||
final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
|
||||
) {
|
||||
for (final CSVRecord record : parser) {
|
||||
final String string = record.get("SomeColumn");
|
||||
...
|
||||
}
|
||||
} finally {
|
||||
parser.close();
|
||||
reader.close();
|
||||
}</source>
|
||||
</section>
|
||||
<!-- ================================================== -->
|
||||
|
|
Loading…
Reference in New Issue