Commons-csv is a toolkit provided by the Apache Open source organization for reading and writing CSV files, simpler, straightforward code:
Package com.gujin.csv;
Import Java.io.FileReader;
Import Java.io.PrintWriter;
Import Org.apache.commons.csv.CSVFormat;
Import Org.apache.commons.csv.CSVParser;
Import Org.apache.commons.csv.CSVPrinter;
Import Org.apache.commons.csv.CSVRecord;
Import Org.junit.Test; public class Csvtest {@Test public void write () throws Exception {appendable out = new PrintWriter ("file.
CSV ");
Csvprinter printer = CSVFormat.DEFAULT.withHeader ("UserId", "UserName"). Print (out);
for (int i = 0; i < i++) {Printer.printrecord ("userId" + I, "userName" + i);
} printer.flush ();
Printer.close ();
@Test public void Read () throws Exception {FileReader reader = new FileReader ("File.csv");
Csvparser parser = CSVFormat.DEFAULT.withHeader ("UserId", "UserName"). Parse (reader); for (Csvrecord record:parser) {System.out. println (Record.get ("userId") + ":" + RecOrd.get ("UserName"));
} reader.close (); }
}