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

> Writes Lua string bytes to a file inside the workspace, creating missing parent directories and replacing the file contents if the file already exists.

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

  ## Aliases

  * `writefileasync`

  ## Arguments

  <ParamField path={"path"} type={"string"} required>
    File path resolved inside the workspace after separator normalization, workspace-boundary checks, and filename/extension checks. Absolute paths are accepted only if they resolve inside the workspace.
  </ParamField>

  <ParamField path={"content"} type={"string"} required>
    Lua string bytes to write. The data is written in binary truncate mode; writefile does not add newlines, BOM bytes, null terminators, or other extra bytes.
  </ParamField>

  ## Example

  Write bytes to a workspace file and replace any existing contents.

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

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

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