Please try the below provided code snippet on your end to get the number of columns in a CSV.
Java
Workbook book = new Workbook(myDir + “Input.csv”);
Worksheet sheet = book.getWorksheets().get(0);
Cells cells = sheet.getCells();
//For total number of data columns, please add 1 to the MaxDataColumn value //because columns have zero based index therefore when MaxDataColumn value is 1 //that means there are total 2 data columns in the worksheet/CSV
System.out.println((cells.getMaxDataColumn() + 1));
Please feel free to write back in case you need our further assistance.