Skip to content

Latest commit

 

History

History
70 lines (50 loc) · 3.17 KB

File metadata and controls

70 lines (50 loc) · 3.17 KB

Simple Java CSV Reader / Writer

Maven Central javadoc ChangeLog Documentation CodeCov CI GitHub License

This package provides some Java classes to help with the reading and writing of CSV files using Java annotations.

Enjoy. Gray Watson

Quick Example:

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 */);

Maven Configuration

Maven packages are published via Maven Central

<dependency>
	<groupId>com.j256.simplecsv</groupId>
	<artifactId>simplecsv</artifactId>
	<version>2.7</version>
</dependency>

ChangeLog Release Notes

See the ChangeLog file.