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

Write CSV 

opencsv is a free and open source library for reading and writing CSV files in Java. We need to have opencsv-2.3.jar or later versions in classpath. The following example shows writing a CSV file using opencsv.

File Name  :  
com/bethecoder/tutorials/open_csv/tests/WriteCSV.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.open_csv.tests;

import java.io.IOException;
import java.io.StringWriter;

import au.com.bytecode.opencsv.CSVWriter;

public class WriteCSV {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {
    StringWriter sw = new StringWriter();
    CSVWriter writer = new CSVWriter(sw);
    String [] data = "ONE""TWO""THREE""FOUR" };
    
    for (int i = ; i < ; i ++) {
      writer.writeNext(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"


                    Print

   



Books Recommendation

 
 
bl  br