Writing a CSV file with Java using OpenCSV


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

URL: http://opencsv.sourceforge.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.