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

# fileCreate

> 建立檔案並將指定資料寫入檔案，可控制編碼和寫入模式。

在磁碟上的指定路徑建立檔案，並可選擇寫入該檔案。

## 必需的參數

* **file**: 要建立的檔案的完整路徑（包括檔名）。

## 可選的參數

* **force**：控制操作是否在 **file** 參數中設定的路徑中建立丟失的目錄。 允許的值為 `true` 和 `false`。 預設值為 `true`。
* **data**：要寫入檔案的資料。
* **mode**：寫入模式。 允許的值為 `truncate` 和 `append`。 預設值為 `truncate`，如果目的檔案已存在，則會覆蓋檔案內容。
* **encoding**：建立檔案時使用的編碼。 允許的值由所使用的 JVM/OS 確定。 預設為 `UTF-8`。

## 輸出屬性

* **file:file**: 建立檔案的完整路徑。
* **file:cdate**: 檔案的建立日期。

## 範例

```xml theme={null}
<!-- Setting the file location and data on the input item -->
<arc:set attr="input.file" value="/tmp/myfiles/cars.json"/>
<arc:setc attr="input.data">{
  "Cars": [
    {
      "Make": "Toyota",
      "Model": "Camry",
      "Type": "Sedan"
    },
    {
      "Make": "Toyota",
      "Model": "Corolla",
      "Type": "Sedan"
    }
  ]
}
</arc:setc>

<!-- Calling fileCreate and passing in the input item -->
<arc:call op="fileCreate" in="input" out="result">
  <!-- Optional: Logging information about the created file to the application log -->
	<arc:set attr="_log.info" value="A file with the timestamp of [result.file:cdate] was created and written to this path: [result.file:file]"/>  
</arc:call> 
```
