How can I read a simple text file, processing each line of the file?

ColdFusion makes it easy to read a file using the <cfloop> tag. By using the file attribute, you can tell <cfloop> to iterate over each line of a file. This sample reads in a text file and displays each line:

<cfset myfile = expandPath("./dump.txt")>
<cfloop index="line" file="#myfile#">
	<cfoutput>
	The current line is #line# <br />
	</cfoutput>
</cfloop>

This question was written by Hal Helms
It was last updated on July 1, 2008.

Categories

File and Directory Access

Comments

comments powered by Disqus