If you specify a file path, writes the entire content to the file. If you specify a file object, writes text or binary data to the file object.
FileWrite(filepath
,data
[,charset
]) OR FileWrite(fileobj
,data
)
FileCopy, FileDelete, FileExists, FileMove, cffile
ColdFusion 8: Added this function.
Parameter |
Description |
---|---|
charset |
The character encoding in which the file contents is encoded. The following list includes commonly used values:
If the file starts with a byte order mark and you set this attribute to a conflicting character encoding, ColdFusion generates an error. |
data |
Content of the file or file object to create. |
fileobj |
Name of the file object to write. |
filepath |
Pathname of the file to write. If not an absolute path (starting a with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function. |
<h3>FileWrite Example</h3> <!--- This example gets the email addresses of employees, ---> <!--- creates a file object that contains the e-mail addresses, ---> <!--- read the file object, and then creates a text file with a ---> <!--- list of e-mail addresses. ---> <cfquery name="getemployees" datasource="cfdocexamples"> SELECT EMAIL FROM Employees </cfquery> <cfset companymail = ""> <cfloop query = "getemployees"> <cfset companymail = companymail & #EMAIL# & ";" & " "> </cfloop> <cfscript> FileWrite("mail_list", "#companymail#"); mlist = FileRead("mail_list"); FileWrite("c:\temp\mail_list.txt", "#mlist#"); </cfscript>