try (CSVReader reader = new CSVReader(new FileReader("data.csv"))) {
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
for (String cell : nextLine) {
}
}
} catch (IOException e) {
}
try (CSVWriter writer = new CSVWriter(new FileWriter("data.csv"))) {
String[] row1 = {"John", "Doe", "john.doe@example.com"};
String[] row2 = {"Jane", "Smith", "jane.smith@example.com"};
writer.writeNext(row1);
writer.writeNext(row2);
} catch (IOException e) {
}
CSVParser parser = new CSVParserBuilder().withSeparator('\t').build();
CSVReader reader = new CSVReaderBuilder(new FileReader("data.csv"))
.withCSVParser(parser)
.build();
public class Person {
@CsvBindByPosition(position = 0)
private String firstName;
@CsvBindByPosition(position = 1)
private String lastName;
@CsvBindByPosition(position = 2)
private String email;
}