-
Notifications
You must be signed in to change notification settings - Fork 8
Basics
ybonnel edited this page Aug 13, 2012
·
14 revisions
In this page you will find informations on basics usage of CsvEngine.
/**
* Class representing a Dog.
* This class is mapped to a CSV File.
*/
// This annotation is use to declare Dog as a class mapped to a CSV File.
// You can change default separator with : @CsvFile(separator = ";")
@CsvFile
public class Dog {
// The "name" field is mapped to a column in CSV named "name"
@CsvColumn("name")
private String name;
// The "race" field is mapped to a column in CSV named "race"
@CsvColumn("race")
private String race;
@CsvColumn("proprietary")
// The "proprietary" field is mapped to a column in CSV named "proprietary"
private String proprietary;
@Override
public String toString() {
return "Dog{" +
"name='" + name + '\'' +
", race='" + race + '\'' +
", proprietary='" + proprietary + '\'' +
'}';
}
}
CsvEngine engine = new CsvEngine(Dog.class);
List<Dog> dogs = engine.parseInputStream(csvFile, Dog.class).getObjects();
engine.writeFile(writer, dogs, Dog.class);
engine.parseFileAndInsert(new InputStreamReader(stream), Dog.class, new InsertObject<Dog>() {
@Override
public void insertObject(Dog dog) {
System.out.println(dog.toString());
}
});
You can see samples in CsvEngineSample.