Skip to content

j256/simplecsv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Java CSV Reader / Writer

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.6</version>
</dependency>

ChangeLog Release Notes

See the ChangeLog.txt file.