<CFFILE ACTION="Read" FILE="file_name" VARIABLE="var_name">
You can use the CFFILE tag to read an existing text file. The file is read into a dynamic parameter you can use anywhere in the page like any other dynamic parameter. For example, you could read a text file and then insert its contents into a database. Or you could read a text file and then use one of the find and replace functions to modify its contents.
Required. The text file to be read (with directory location).
Required. The name of the variable that will contain the contents of the text file after it has been read.
The following example creates a variable named "Message" that will contain the contents of the file message.txt.
<CFFILE ACTION="Read" FILE="c:\web\message.txt" VARIABLE="Message">
The variable "Message" could then be used in the page. For example, you could display the contents of the message.txt
file in the final Web page:
<CFOUTPUT>#File.Message#</CFOUTPUT>
ColdFusion supports a number of powerful functions for manipulating the contents of text files. You can also use variable created by a CFFILE Read operation in ArrayToList and ListToArray functions.
See String Functions and Array Functions for more information about working with strings and arrays.