User Guide
Chapter 14: Managing Files on the Server 227
Reading, Writing, and Appending to a Text File
In addition to managing files on the server, you can use CFFILE to read, create, and
modify text files.
This gives you the ability to
• Create log files.
• Generate static HTML documents.
• Use text files to store information that can be brought into Web pages.
Reading a text file
You can use CFFILE to read an existing text file. The file is read into a dynamic
parameter which you can use anywhere in the application page. 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 the contents.
To read a text file:
1. Create a new file in Studio.
2. Modify the file so that it appears as follows:
<HTML>
<HEAD>
<TITLE>Read a Text File</TITLE>
</HEAD>
<BODY>
Ready to read the file:<BR>
4 <CFFILE ACTION="Read"
4 FILE="C:\inetpub\wwwroot\mine\message.txt"
4 VARIABLE="Message">
<CFOUTPUT>
#Message#
</CFOUTPUT>
</BODY>
</HTML>
3. Replace c:\inetpub\wwwroot\mine\message.txt with the location and name of a
text file on your server.
4. Save the file as readtext.cfm and view it in your browser.
Writing a text file
You can use CFFILE to write a text file based on dynamic content. For example, you
could create static HTML files or log actions in a text file.