import org.apache.commons.csv.*;
try {
CSVParser parser = CSVParser.parse(new File("data.csv"), Charset.defaultCharset(), CSVFormat.DEFAULT);
for (CSVRecord record : parser) {
String field1 = record.get(0);
String field2 = record.get(1);
// ...
System.out.println("Field 1: " + field1);
System.out.println("Field 2: " + field2);
// ...
}
parser.close();
} catch (IOException e) {
e.printStackTrace();
}
import org.apache.commons.csv.*;
try {
CSVPrinter printer = new CSVPrinter(new FileWriter("output.csv"), CSVFormat.DEFAULT);
printer.printRecord("Field 1", "Field 2", "Field 3");
printer.printRecord("Value 1", "Value 2", "Value 3");
// ...
printer.close();
} catch (IOException e) {
e.printStackTrace();
}