2019-10-21 04:22:28 -04:00
---
title: readFile
2021-12-08 02:42:31 -05:00
description: Returns the contents of a file.
2019-10-21 04:22:28 -04:00
date: 2017-02-01
publishdate: 2017-02-01
2021-12-08 02:42:31 -05:00
lastmod: 2021-11-26
2019-10-21 04:22:28 -04:00
categories: [functions]
menu:
docs:
parent: "functions"
keywords: [files]
2021-12-08 02:42:31 -05:00
signature: ["os.ReadFile PATH", "readFile PATH"]
2019-10-21 04:22:28 -04:00
workson: []
hugoversion:
2021-12-08 02:42:31 -05:00
relatedfuncs: ['os.FileExists','os.ReadDir','os.Stat']
2019-10-21 04:22:28 -04:00
deprecated: false
aliases: []
---
2021-12-08 02:42:31 -05: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` ]({{< relref "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
2021-12-08 02:42:31 -05:00
For more information on using `readDir` and `readFile` in your templates, see [Local File Templates ]({{< relref "/templates/files" >}} ).