I am looking out for Java open source API which ease CSV reading/writing and it's value calculation. I am having 3 CSV files, which I need raw read and make calculation and write into final CSV file.
-
This is not a place to ask people to code for you. Your question is also vague (bad grammar making it hard to understand)Mark Jeronimus– Mark Jeronimus2016-05-08 14:21:54 +00:00Commented May 8, 2016 at 14:21
-
you really do not need package you can just read csv just look at this example stackoverflow.com/questions/14274259/java-read-csv-with-scanner and write stackoverflow.com/questions/30073980/… when that said you can have a look at opencsv.sourceforge.net and just google search for reading/writing to CSV file in JAVAMaytham Fahmi– Maytham Fahmi2016-05-08 15:08:23 +00:00Commented May 8, 2016 at 15:08
-
stackoverflow.com/questions/14226830/…Maytham Fahmi– Maytham Fahmi2016-05-08 15:34:23 +00:00Commented May 8, 2016 at 15:34
Add a comment
|
1 Answer
uniVocity-parsers has a great API that helps you process all sorts of CSV inputs.
Here's an example to read a given set of columns in a file:
CsvParserSettings settings = new CsvParserSettings(); //many options here, check the tutorial
parserSettings.selectFields("Foo", "Price", "Blah"); //get only those fields you are interested in
CsvParser parser = new CsvParser(settings);
List<Record> allRecords = parser.parseAllRecords(new File("/path/to/file.csv"));
double sumOfPrices = 0.0;
for (Record record : allRecords) {
//Here we read the "price" column, using the "0,00" format mask, and decimal separator set to comma.
Double price = record.getDouble("price", "0,00", "decimalSeparator=,");
if (price != null) {
sumOfPrices += price;
}
}
Disclosure: I am the author of this library. It's open-source and free (Apache V2.0 license).