Description

Appends text or contents of an object to an in-memory text file.

You can also use this function as an alternative to the cffile tag with the action="append" attribute.

Returns

Void.

Category

Function Syntax

FileAppend(String filePath, Object data, String charset, Boolean addNewLine)

See also

History

ColdFusion (2018 release) Update 4, ColdFusion (2016 release) Update 11: Added support for this function.

Parameters

Parameter

Required (Yes/No)

Description

filePath

Yes

An absolute path to an on-disk or in-memory text file on the server.

data Yes The file object or string from which to read.

charset

No

The character encoding in which the file contents is encoded. The following list includes commonly used values:

  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16
    If the file starts with a byte order mark and you set this attribute to a conflicting character encoding, ColdFusion generates an error.
addNewLine No Boolean value that indicates whether a new line is to be added to the contents of the file.

Example

<cfscript>
    theDir=GetDirectoryFromPath(GetCurrentTemplatePath())
    theFolder=theDir & "file.txt"
    fileData="The quick brown fox jumps over the lazy dog."
    FileAppend(filePath=theFolder,data=fileData,charset="UTF-8",addNewLine="yes")
</cfscript>

In the snippet above, the parameter addNewLine adds the information that is specified in the parameter data. As many times you run this snippet, the information gets added as a new line in the output file.

本产品经 Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License 许可  Twitter™ 与 Facebook 中的内容不在 Creative Commons 的条款约束之下。

法律声明   |   在线隐私策略