<dependency>
<groupId>com.github.mnadeem</groupId>
<artifactId>simplecsv</artifactId>
<version>1.3</version>
</dependency>
implementation 'com.github.mnadeem:simplecsv:1.3'
import com.github.mygreen.supercsv.io.CsvAnnotationBeanReader;
import com.github.mygreen.supercsv.prefs.CsvPreference;
public class CSVReaderExample {
public static void main(String[] args) throws Exception {
String csvFilePath = "path/to/csv/file.csv";
try (CsvAnnotationBeanReader<MyCSVBean> csvReader = new CsvAnnotationBeanReader<>(
MyCSVBean.class, new FileReader(csvFilePath), CsvPreference.STANDARD_PREFERENCE)) {
String[] header = csvReader.getHeader();
MyCSVBean csvBean;
while ((csvBean = csvReader.read()) != null) {
System.out.println(csvBean.toString());
}
}
}
}
import com.github.mygreen.supercsv.io.CsvAnnotationBeanWriter;
import com.github.mygreen.supercsv.prefs.CsvPreference;
public class CSVWriterExample {
public static void main(String[] args) throws Exception {
String csvFilePath = "path/to/csv/file.csv";
try (CsvAnnotationBeanWriter<MyCSVBean> csvWriter = new CsvAnnotationBeanWriter<>(
MyCSVBean.class, new FileWriter(csvFilePath), CsvPreference.STANDARD_PREFERENCE)) {
csvWriter.writeHeader();
csvWriter.write(new MyCSVBean("John", "Doe"));
csvWriter.write(new MyCSVBean("Jane", "Smith"));
}
}
}