RSS Feed for This PostCurrent Article

opencsv: Open Source Java CSV Library

OpenCSV is a Java CSV parser library.

opencsv supports all the basic csv-type things you’re likely to want to do:

  • Arbitrary numbers of values per line
  • Ignoring commas in quoted elements
  • Handling quoted entries with embedded carriage returns (ie entries that span multiple lines)
  • Configurable separator and quote characters (or use sensible defaults)
  • Read all the entries at once, or use an Iterator style model
  • Creating csv files from String[] (ie. automatic escaping of embedded quote chars)

Sample code

CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
        // nextLine[] is an array of values from the line
        System.out.println(nextLine[0] + nextLine[1] + "etc...");

Popularity: 1% [?]

Trackback URL

RSS Feed for This PostPost a Comment