Recently, there was a requirement in the work to export CSV format files, before encountering similar requirements, finally found on Google Opencsv, and provide Java API
Opencsv Address: https://code.google.com/p/opencsv/
The site provides a complete sample code, here only a CSV read and write sample code, others, please move to the official website to see.
Import Java.util.Arrays; public class Csvafter {//define format of CSV file one time and use everywhere//human READABL
E configuration private static final CSV CSV = CSV. Separator (';') . quote (' \ '). Skiplines (1). CharSet ("UTF-8"). C
Reate (); Don't throw checked exceptions public static void main (string[] args) {String fileName = ' tes
T.csv ";
Csvwriter'll be closed after the end of processing csv.write (FileName, New Csvwriteproc () {
public void process (Csvwriter out) {out.writenext ("Header1", "Header2");
Out.writenext ("V11", "V12");
Out.writenext ("V21", "v22");
}
}); Csvreader'll be closed after the end of processing//less code to process CSV content-> Less bugs Csv.read (fileName, New Csvreadproc () {public void procrow (int rowIndex,
String ... values) {System.out.println (RowIndex + "#" + arrays.aslist (values));
}
}); }
}