2019-10-21 04:22:28 -04:00
---
2023-10-20 03:42:39 -04:00
title: os.ReadFile
linkTitle: readFile
2021-12-08 02:42:31 -05:00
description: Returns the contents of a file.
2019-10-21 04:22:28 -04:00
categories: [functions]
2023-10-20 03:42:39 -04:00
keywords: []
2019-10-21 04:22:28 -04:00
menu:
docs:
2023-05-22 10:43:12 -04:00
parent: functions
2023-10-20 03:42:39 -04:00
function:
aliases: [readFile]
returnType: string
signatures: [os.ReadFile PATH]
relatedFunctions:
- os.FileExists
- os.Getenv
- os.ReadDir
- os.ReadFile
- os.Stat
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
{{ os.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 ).