Reputation: 1874
Can someone please provide me with an example of reading a CSV file with the Apache commons CSVParser class? I see countless examples that use the outdated (I think) API that has been impossible to find.
Everywhere I look, I see this:
File csvData = new File("/path/to/csv");
CSVParser parser = CSVParser.parse(csvData, CSVFormat.RFC4180);
for (CSVRecord csvRecord : parser) {
...
}
But nowhere can I find a jar file that has a CSVParser.parse() method that takes those parameters. The one that takes a File object, also takes a Charset parameter after it. All over the place I see the API describe that literally doesn't seem to exist. I'm guessing it was a pre-1.0 API that they removed once 1.0 was released. I've tried 1.0, 1.1. and 1.2 in my pom file dependency, but they all have the method with the Charset parameter.
Upvotes: 6
Views: 10589
Reputation: 1874
I ended up just doing this:
CSVParser csvFileParser = CSVFormat.DEFAULT.parse(new FileReader(new File("/path/to/csv")));
Still blows my mind that all articles and official apache documentation show examples using a method that doesn't appear to exist.
Upvotes: 12