Wednesday, May 11, 2022

openCSV in ColdFusion and Lucee

 The opencsv project at  is a nice overall java based csv parser library that can automatically support qualified strings that contain comma's.  The below code works in ColdFusion 2021 as is with the opencsv.jar file but needs an additional jar with Lucee 5.3.9.

ColdFusion and Lucee: 

Grab the source from and run mvn to produce the jar.  I used version 5.6.


Download the apache commons lang3 source from and compile with maven.


Put the jar(s) in the lib folder of the server or use a jar loader.  start up the server and run the following test (adjust the path to your sample csv data file). which should produce the data below (excluding the other dumps)


    csvFile ="#expandPath('.')#/csv_data/addresses.csv";
    csvData = [];

    fileReader = createobject("java","").init(csvFile);


    csvReader = createObject("java","com.opencsv.CSVReader").init(fileReader);
    csvData = csvReader.readAll();


No comments:

Post a Comment