> ## 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> 
```
