Thursday, July 19, 2007

CSV reading from Java

If you need to process CSV files, for example as a result of an export from Excel or OpenOffice.org Calc, then try CsvReader, an LGPL Java-library. It works remarkably simple:
CsvReader reader = new CsvReader("input.csv");

// Read all headers (the first line)
reader.readHeaders();

// Read all remaining lines
while (reader.readRecord()) {
String productID = reader.get("ProductID");
// etc.
}

reader.close();
I'm using CsvReader 2.0, released in December 2006.

No comments:

Post a Comment