# os.ReadFile
> 返回文件的内容。
- 官方英文原文：https://gohugo.io/functions/os/readfile/
- 本页规范地址：https://hugozh.cn/functions/os/readfile/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：os.ReadFile PATH
- 返回类型：string
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

---
`os.ReadFile` 函数先尝试相对于项目目录的根解析路径。如果找不到匹配的文件，它会尝试相对于 [`contentDir`][] 解析路径。路径开头的分隔符（`/`）是可选的。

假设项目目录根下有一个名为 README.md 的文件：

```md
This is **bold** text.
```

以下模板代码：

```go-html-template
{{ readFile "README.md" }}
```

输出：

```html
This is **bold** text.
```

注意，`os.ReadFile` 返回的是原始（未经解释）内容。

[`contentDir`]: /configuration/all/#contentdir

