0

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.

3

1 Answer 1

0

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).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.