Search code examples
coldfusioncoldfusion-9

Coldfusion reading specific line from text file


I want to read only line #2 from a text file, but unfortunately have found no clue how to do this. Are there any solutions besides looping and breaking when the row is found?


Solution

  • Step 1 - Read the file to a variable:

    <cffile action = "read" file = "yourFile" variable = "fileContents">
    

    Step 2 - Treat the variable as a chr(10) delimited list and get the second row.

    line2 = ListGetAt(fileContents, 2, chr(10));