I am converting csv file to excel using CsvMapReader. But for few files am getting exception as below:
Exception in thread "main" org.supercsv.exception.SuperCsvException: the nameMapping array and the sourceList should be the same size (nameMapping length = 0, sourceList size = 11) context=null
Tried many alternatives but not able to resolve.
Please help to resolve this, pasting a part of my code:
String fName = filename;
String outputFile = "";
Workbook wb = new HSSFWorkbook();
FileOutputStream fileOut;
if(!new File(filename).exists()){
System.out.println("File Not Found");
} else{
try {
ICsvMapReader csvMapReader = new CsvMapReader(new FileReader(
fName), CsvPreference.EXCEL_PREFERENCE);
final String[] headers = csvMapReader.getHeader(true);
Map csvRow;
outputFile = fName.substring(0, fName.length() - 4);
fileOut = new FileOutputStream(outputFile + ".xls");
Sheet sheet = wb.createSheet("products");
int rowNo = 0;
createExcelHeader(sheet, rowNo, fName); //Seperate function
**while ((csvRow = csvMapReader.read()) != null) {** //getting exception at this point
rowNo++;
Row excelRow = sheet.createRow(rowNo);
createExcelRow(csvRow, excelRow, fName); //Seperate function
}
csvMapReader.close();
wb.write(fileOut);
fileOut.close();
System.out.println("*");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}