Reads a text file. The file is read into a dynamic parameter that 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 the find and replace functions to modify its contents.
Note Using |
<cffile action = "read" file = "full_path_name" variable = "var_name">
Attribute |
Description |
---|---|
file |
Required. The full pathname of the text file to be read. |
variable |
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 " to 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>#Message#</cfoutput>
ColdFusion supports a number of powerful functions for manipulating the contents of text files. You can also use the variable created by a cffile action = "read"
operation in ArrayToList and ListToArray functions.
For more information about working with strings and arrays, see "String functions" and "Array functions".