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.

maytham-ɯɐɥʇʎɐɯ
  • 21,551
  • 10
  • 85
  • 103
Prasad
  • 29
  • 2
  • 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 May 08 '16 at 14:21
  • you really do not need package you can just read csv just look at this example http://stackoverflow.com/questions/14274259/java-read-csv-with-scanner and write http://stackoverflow.com/questions/30073980/java-writing-strings-to-a-csv-file when that said you can have a look at http://opencsv.sourceforge.net/ and just google search for reading/writing to CSV file in JAVA – maytham-ɯɐɥʇʎɐɯ May 08 '16 at 15:08
  • http://stackoverflow.com/questions/14226830/java-csv-file-easy-read-write – maytham-ɯɐɥʇʎɐɯ May 08 '16 at 15:34

1 Answers1

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

Jeronimo Backes
  • 5,701
  • 2
  • 20
  • 28