This package provides some Java classes to help with the reading and writing of CSV files using Java annotations.
- For more information, visit the home page.
- In the sourcecode there is a simple working example program.
- Online documentation can be found off the home page including full Javadocs.
- The source is available from the git repository.
- Maven packages are published via
- Javadocs:
Enjoy. Gray Watson
Define your entity with the fields marked with the @CsvColumn annotation, can also mark get/set methods:
public class Account {
@CsvColumn(columnName = "Name")
private String name;
@CsvColumn(columnName = "Account Number")
private long number;
...
}
Create a CSV processor for the Account class.
CsvProcessor<Account> csvProcessor = new CsvProcessor<Account>(Account.class);
Write out all of the accounts from a list of them to a CSV file with a header:
File csvFile = new File(CSV_FILE_PATH);
csvProcessor.writeAll(csvFile, accountList, true /* write header */);
This generates the following output:
"Name","Account Number"
"Bill Smith",1
"Foo Bar",2
"Jim Jimston",3
Now read those accounts back in with an optional error handler:
List<Account> readAccounts = csvProcessor.readAll(csvFile, null /* error handler */);
<dependency>
<groupId>com.j256.simplecsv</groupId>
<artifactId>simplecsv</artifactId>
<version>2.6</version>
</dependency>
See the ChangeLog.txt file.