0
public class CSVRead {

private static List<Bean> CsvToBean(String csvFileName) throws IOException {

    CSVReader csvReader = new CSVReader(new FileReader(csvFileName));
    CsvToBean<Bean> bean = new CsvToBean<Bean>();
    ColumnPositionMappingStrategy<Bean> strategy = new ColumnPositionMappingStrategy<Bean>();
    strategy.setType(Bean.class);
    strategy.setColumnMapping(new String[] { "email_Address", "first_name", "last_name" });
    // Parse the CSV
    List<Bean> list = bean.parse(strategy, csvReader);
    return list;
}

public static void main(String[] args) throws IOException {
    Bean b = null;//bean class 
    String csvFileName = "E:\\jeeworkspace\\demo.csv";
    List<Bean> l = CsvToBean(csvFileName);
    for (Object o : l) {
        b = (Bean) o;
        System.out.println(b.toString);
    }
}

here in the above code it is parsing csv into a bean object. but these csv contains header like email,first_name...i dont want to add this into the bean object how can i do it without removing headers from a file.

Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211
iKing
  • 667
  • 10
  • 15
  • 1
    What class is CSVReader ? Is this from a library or your own code? – Wim Deblauwe May 22 '14 at 09:34
  • this is the class i wrote not the library one. – iKing May 22 '14 at 09:38
  • This code is working fine but problem is the headers in the csv are also including while parsing. i want result in which the headers in the file doesn't include in the bean object. – iKing May 22 '14 at 09:47

0 Answers0