Read bean objects from a csv file or write bean objects to a csv file.
- Read bean objects from a csv file.
- Write bean objects to a csv file.
@CsvColumn
indicates the column names, column order and column format.
Please refer to the following examples.
- How to use
@CsvColumn
?
public class Worker { @CsvColumn(name="id", orderKey="A") private String id; @CsvColumn(name="firstName", orderKey="B") private String firstName; @CsvColumn(name="lastName", orderKey="C") private String lastName; @CsvColumn(name="birthday", orderKey="D", format="yyyyMMdd") private Date birthday; // setters and getters }
- How to read bean objects?
CSVReader csvReader = new CSVReader(new FileReader("beancsv.csv")); List workers = BeanCsv.parseBeans(csvReader, Worker.class, true); csvReader.close();
- How to write bean objects?
CSVWriter csvWriter = new CSVWriter(new FileWriter(new File("beancsv.csv"))); BeanCsv.writeHeader(csvWriter, Worker.class); List workers = new ArrayList<>(); workers.add(new Worker()); workers.add(new Worker()); BeanCsv.write(csvWriter, workers); csvWriter.close();
<dependency>
<groupId>com.github.zjulzq</groupId>
<artifactId>bean-csv</artifactId>
<version>0.0.3</version>
</dependency>
We accept PRs via github. There are some guidelines which will make applying PRs easier for us:
- No tabs! Please use spaces for indentation.
- Respect the code style.
- Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
- Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running
mvn clean test
.
Code is under the Apache Licence v2.