@@ -72,7 +72,7 @@ for (CSVRecord record : records) {
7272 </p >
7373 <source >final URL url = ...;
7474final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
75- final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader() );
75+ final CSVParser parser = CSVFormat.EXCEL.builder().setHeader().build().parse(reader );
7676try {
7777 for (final CSVRecord record : parser) {
7878 final String string = record.get("SomeColumn");
@@ -118,7 +118,7 @@ for (CSVRecord record : records) {
118118 Indices may not be the most intuitive way to access record values. For this reason it is possible to
119119 assign names to each column in the file:
120120 <source >Reader in = new FileReader(" path/to/file.csv" );
121- Iterable< CSVRecord> records = CSVFormat.RFC4180.withHeader( "ID", "CustomerNo", "Name").parse(in);
121+ Iterable< CSVRecord> records = CSVFormat.RFC4180.builder().setHeader( "ID", "CustomerNo", "Name").build( ).parse(in);
122122for (CSVRecord record : records) {
123123 String id = record.get("ID");
124124 String customerNo = record.get("CustomerNo");
@@ -136,7 +136,7 @@ for (CSVRecord record : records) {
136136 ID, CustomerNo, Name
137137}
138138Reader in = new FileReader(" path/to/file.csv" );
139- Iterable< CSVRecord> records = CSVFormat.RFC4180.withHeader( Headers.class).parse(in);
139+ Iterable< CSVRecord> records = CSVFormat.RFC4180.builder().setHeader( Headers.class).build( ).parse(in);
140140for (CSVRecord record : records) {
141141 String id = record.get(Headers.ID);
142142 String customerNo = record.get(Headers.CustomerNo);
@@ -149,7 +149,7 @@ for (CSVRecord record : records) {
149149 Some CSV files define header names in their first record. If configured, Apache Commons CSV can parse
150150 the header names from the first record:
151151 <source >Reader in = new FileReader(" path/to/file.csv" );
152- Iterable< CSVRecord> records = CSVFormat.RFC4180.withHeader ().withSkipHeaderRecord( true).parse(in);
152+ Iterable< CSVRecord> records = CSVFormat.RFC4180.builder ().setHeader().setSkipHeaderRecord( true).build( ).parse(in);
153153for (CSVRecord record : records) {
154154 String id = record.get("ID");
155155 String customerNo = record.get("CustomerNo");
@@ -163,13 +163,13 @@ for (CSVRecord record : records) {
163163 To print a CSV file with headers, you specify the headers in the format:
164164 </p >
165165 <source >final Appendable out = ...;
166- final CSVPrinter printer = CSVFormat.DEFAULT.withHeader( "H1", "H2").print(out)
166+ final CSVPrinter printer = CSVFormat.DEFAULT.builder().setHeader( "H1", "H2").build(). print(out);
167167 </source >
168168 <p >
169169 To print a CSV file with JDBC column labels, you specify the ResultSet in the format:
170170 </p >
171171 <source >final ResultSet resultSet = ...;
172- final CSVPrinter printer = CSVFormat.DEFAULT.withHeader( resultSet).print(out)
172+ final CSVPrinter printer = CSVFormat.DEFAULT.builder().setHeader( resultSet).build(). print(out);
173173 </source >
174174 </subsection >
175175 </section >
0 commit comments