> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# fileWrite

> 将数据写入文件，支持追加和指定编码。

将编码数据写入新文件或现有文件。

## 必需的参数

* **file**: 要写入的文件的完整路径（包括文件名）。 如果该文件不存在，则创建该文件。
* **data**: 要写入文件的数据。

## 可选的参数

* **force**：控制操作是否在文件参数中设置的路径中创建丢失的目录。 允许的值为`true`和`false`。 默认值为`true`。
* **mode**：写入模式。 允许的值为`truncate`和`append`。 默认值为`truncate`，如果目标文件已存在，则会覆盖文件的内容。
* **encoding**：创建文件时使用的编码。 允许的值由 JVM/操作系统决定。 默认为`UTF-8`。

## 输出属性

* **file:file**: 写入文件的完整路径。
* **file:cdate**: 文件的修改日期。

## 示例

```xml theme={null}
<!-- Setting the target file, mode and data on the input item. This example pulls data from existing message headers to append to a csv file. -->
<arc:set attr="input.file" value="/tmp/orders.csv"/>
<arc:set attr="input.mode" value="append" />
<arc:set attr="input.data">[header:orderno],[_|now('MM-dd-yyyy HH:mm')],[header:itemsku],[header:itemqty]\n</arc:set>

<!-- Calling fileWrite and passing in the input item -->
<arc:call op="fileWrite" in="input" out="result">
  <!-- Optional: Logging information about the modified file to the application log -->
  <arc:set attr="_log.info" value="The [result.file:file] file was updated at [result.file:cdate] with a new order."/>  
</arc:call> 
```
