2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: os.ReadFile
2021-12-08 02:42:31 -05:00
description: Returns the contents of a file.
2023-12-04 09:14:18 -05:00
categories: []
2023-10-20 03:42:39 -04:00
keywords: []
2023-12-04 09:14:18 -05:00
action:
2023-10-20 03:42:39 -04:00
aliases: [readFile]
2023-12-04 09:14:18 -05:00
related:
- functions/os/FileExists
- functions/os/Getenv
- functions/os/ReadDir
- functions/os/Stat
2023-10-20 03:42:39 -04:00
returnType: string
signatures: [os.ReadFile PATH]
aliases: [/functions/readfile]
2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
2023-05-22 10:43:12 -04:00
The `os.ReadFile` function attempts to resolve the path relative to the root of your project directory. If a matching file is not found, it will attempt to resolve the path relative to the [`contentDir` ](/getting-started/configuration#contentdir ). A leading path separator (`/`) is optional.
2019-10-21 04:22:28 -04:00
2021-12-08 02:42:31 -05:00
With a file named README.md in the root of your project directory:
2019-10-21 04:22:28 -04:00
2021-12-08 02:42:31 -05:00
```text
This is **bold** text.
2019-10-21 04:22:28 -04:00
```
2021-12-08 02:42:31 -05:00
This template code:
```go-html-template
2023-12-04 09:14:18 -05:00
{{ readFile "README.md" }}
2019-10-21 04:22:28 -04:00
```
2021-12-08 02:42:31 -05:00
Produces:
```html
This is **bold** text.
```
2019-10-21 04:22:28 -04:00
2021-12-08 02:42:31 -05:00
Note that `os.ReadFile` returns raw (uninterpreted) content.
2019-10-21 04:22:28 -04:00
2023-05-22 10:43:12 -04:00
For more information on using `readDir` and `readFile` in your templates, see [Local File Templates ](/templates/files ).