<configuration>
<file path="data.csv" delimiter="," validate="true">
<fields>
<field name="id" type="int" nullable="false" />
<field name="name" type="string" maxLength="50" nullable="false" />
<field name="age" type="int" nullable="true" />
</fields>
</file>
</configuration>
public class Person {
private int id;
private String name;
private int age;
// getters and setters
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
public class FlatFileProcessor {
public static void main(String[] args) {
try {
Configuration configuration = new Configuration("config.xml");
FlatFileReader reader = new FlatFileReader(configuration);
List<Person> persons = new ArrayList<>();
while (reader.hasNext()) {
Person person = reader.read(Person.class);
persons.add(person);
}
for (Person person : persons) {
System.out.println(person);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}