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