Sep
20
2005

opencsv 0.1 – Yet another Java CSV parser (but under an Apache 2.0 license)

Yeah. I know. Why is *anyone* even considering building yet another CSV parser for Java? You got me, but I am. Go figure. The reason is that I haven’t been able to find a tiny CSV parsing class that’s available under a commercial friendly license.

For some reason, all of the ones I’ve come across are a strict “GPL or buy a commercial license” type deal. Well, it’s a CSV parser – how hard could it be? (always a fatal question, since my effort doesn’t handle a lot of the commercial features, but at least it handles the common cases). So here’s my afternoon’s effort to at least get you started.

The quick case:

   CSVReader myReader = new CSVReader(yourFileReaderOrWhatever);
   List entries = myReader.readAll(); // a List of String[]
   // .... iterate and enjoy

Or, if you’d prefer a pull model to conserve memory…. use the readNext() method to get a String[] for the next line, and you're all done when you hit a null.

This version is very bare bones. Supports double-quoted elements, and that's about it. No comment support yet. Probably heaps of edge cases aren't handled. No need to whinge. It is, at least, an Apache 2.0 licensed CSV parser for Java. Modify to suit.

Enjoy. Download it here.

About the Author: Glen Smith

4 Comments + Add Comment

Leave a comment

Glen Smith

About Glen

Co-author Grails in Action