Posted By

m1b on 08/19/11


Tagged

java csv


Versions (?)

Writing a CSV file with Java using OpenCSV


 / Published in: Java
 

URL: http://opencsv.sourceforge.net

  1. import au.com.bytecode.opencsv.CSVWriter;
  2. import java.io.*;
  3.  
  4. public class Csv {
  5.  
  6. public static void main(String[] main) throws Exception{
  7. BufferedWriter out = new BufferedWriter(new FileWriter("result.csv"));
  8. CSVWriter writer = new CSVWriter(out);
  9. String[] values = {"1","first","second","Third one quoted with a, comma","fourth \"double quotes\"\n line break"};
  10. writer.writeNext(values);
  11. values = new String[]{"2","erst","zweite","Dritte,mit Komma","viertl"};
  12. writer.writeNext(values);
  13. values = new String[]{"3","primero","segundo","tercero","cuarto,con la coma"};
  14. writer.writeNext(values);
  15. out.close();
  16. }
  17. }

Report this snippet  

You need to login to post a comment.