tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 CSV > SUPER CSV > Read CSV As Map

Read CSV As Map 

Super CSV is a free library for reading and writing CSV files in Java. We need to have SuperCSV-1.52.jar, spiffy-0.05.jar or later versions in classpath. The following example shows reading a CSV as a map using Super CSV. The CSV header name is used as key and column data as value.

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.super_csv.tests;

import java.util.Map;

import org.supercsv.prefs.CsvPreference;

public class ReadCSVAsMap {

   @param args
   @throws IOException 
  public static void main(String[] argsthrows IOException {

    String CSV = 
      "name,age,hobby\n" +
      "Sriram,2,Chess\n" +
    CsvMapReader csvReader = new CsvMapReader(
        new StringReader(CSV),
    //Read headers
    String [] headers = csvReader.getCSVHeader(true);
    Map<String, String> row = null;
    while ((row = != null) {


It gives the following output,
{age=2, name=Sriram, hobby=Chess}
{age=29, name=Sudhakar, hobby=Painting}



Books Recommendation

bl  br