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

Write CSV 

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 writing a simple CSV using Super CSV.

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

import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;

import org.supercsv.io.CsvListWriter;
import org.supercsv.prefs.CsvPreference;

public class WriteCSV {

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

    StringWriter sw = new StringWriter();
    CsvListWriter writer = new CsvListWriter(sw, CsvPreference.STANDARD_PREFERENCE);
    List<String> data = Arrays.asList("ONE""TWO""THREE""FOUR");
    
    for (int i = ; i < ; i ++) {
      writer.write(data);
    }
    writer.close();

    System.out.println("Generated CSV : \n");
    System.out.println(sw.toString());
  }

}
   

It gives the following output,
Generated CSV : 

ONE,TWO,THREE,FOUR
ONE,TWO,THREE,FOUR
ONE,TWO,THREE,FOUR
ONE,TWO,THREE,FOUR



 
  


  
bl  br