Coldfusion 8 CSV Parsing the Elegant Way

Not a hard task, but I very much like doing things using the most efficient and straightforward means.

Get the jar from sourceforge, then add it to your favorite Coldfusion class path.


<cfset oFile = CreateObject("java","java.io.FileReader") />
<cfset oFile.init(ExpandPath("some.csv")) />

<cfset oReader = CreateObject("java","au.com.bytecode.opencsv.CSVReader") />
<cfset oReader.init(oFile,",") />
<cfset arrCSV = oReader.readAll() />
<cfdump var="#aData#" />

There are no comments yet, add one below.

Leave a Comment

You must be logged in to post a comment.