This repository was archived by the owner on Jun 3, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,7 +32,28 @@ for (CSVRecord record : records) {
3232 String firstName = record.get("First Name");
3333}</source >
3434 <p >Other formats are available, please consult the Javadoc for <a href =" apidocs/org/apache/commons/csv/CSVFormat.html" >CSVFormat</a > and
35- <a href =" apidocs/org/apache/commons/csv/CSVParser.html" >CSVParser</a >.</p >
35+ <a href =" apidocs/org/apache/commons/csv/CSVParser.html" >CSVParser</a >.
36+ </p >
37+ </section >
38+ <section name =" Handling Byte Order Marks" >
39+ <p >
40+ To handle files that start with a Byte Order Mark (BOM) like some Excel CSV files, you need an extra step to deal with these optional bytes.
41+ You can use the
42+ <a href =" https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/BOMInputStream.html" >BOMInputStream</a >
43+ class from <a href =" https://commons.apache.org/proper/commons-io/" >Apache Commons IO</a > for example:
44+ </p >
45+ <source >final URL url = ...;
46+ final Reader reader = new InputStreamReader(new BOMInputStream(url.openStream()), "UTF-8");
47+ final CSVParser parser = new CSVParser(reader, CSVFormat.EXCEL.withHeader());
48+ try {
49+ for (final CSVRecord record : parser) {
50+ final String string = record.get("SomeColumn");
51+ ...
52+ }
53+ } finally {
54+ parser.close();
55+ reader.close();
56+ }</source >
3657</section >
3758
3859<section name =" Getting the code" >
You can’t perform that action at this time.
0 commit comments