Using SuperCSV to Change Header Values

According to this message about SuperCSV capabilities , can SuperCSV handle header values ​​( only column names ) read from the database?

For example, the following code snippet describes the current state and expected state.

Current state

INPUT

final String[] header = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, header, processors);
}

OUTPUT : file with column names:

firstName, lastName, birthDate
Bob      , Doe     , 02/12/2013  

Expected condition

INPUT :

final String[] header = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, header, processors);
}

// modify the headers
 ??????

OUTPUT : file with changed column names:

First Name, Last Name, Birthday
Bob      , Doe     , 02/12/2013 

Any help is greatly appreciated.

+3
source share
1 answer

, , , , - , beanWriter.write()

, :

final String[] header = new String[] { "First Name", "Last Name", "Birthday"};
final String[] fieldMapping = new String[] { "firstName", "lastName", "birthDate"};

// write the header
beanWriter.writeHeader(header);

// write the beans
for( final CustomerBean customer : customers ) {
   beanWriter.write(customer, fieldMapping , processors);
}
+9

All Articles