
Reading, Writing, and Appending to a Text File
327
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. As a result, you can do the following things:
•
Create log files. (You can also use
cflog
to create and write to 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 local variable
that 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 string replacement functions to modify the contents.
To read a text file:
1
Create a new file in ColdFusion 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>
<cffile action="Read"
file="C:\inetpub\wwwroot\mine\message.txt"
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.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...