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

# writefile

> 将 Lua string bytes 写入 workspace 内的文件，创建 missing parent directories，并在文件已存在时替换 file contents。

<div className="real-function-page">
  ```lua theme={null}
  writefile(path: string, content: string)
  ```

  ## 别名

  * `writefileasync`

  ## 参数

  <ParamField path={"path"} type={"string"} required>
    File path 会在 separator normalization、workspace-boundary checks 和 filename/extension checks 之后解析到 workspace 内。Absolute paths 只有在解析到 workspace 内时才会被接受。
  </ParamField>

  <ParamField path={"content"} type={"string"} required>
    要写入的 Lua string bytes。数据以 binary truncate mode 写入；writefile 不会添加 newlines、BOM bytes、null terminators 或其他 extra bytes。
  </ParamField>

  ## 示例

  向 workspace file 写入 bytes，并替换任何 existing contents。

  ```lua theme={null}
  local path = "examples/config.json"

  writefile(path, '{"enabled":true}')
  print(readfile(path))

  writefile(path, "")
  print(#readfile(path))
  ```
</div>
