---
title: "Discussion on \"Go Cheatsheet - Read & Write File\" | Hashnode"
description: "Discussion on \"Go Cheatsheet - Read & Write File\". Read & Write File\nRead File content\n1, Use ioutil.ReadFile:\ncontent, err := ioutil.ReadFile(\"sample.txt\")\n\n2, Open file first (in read-only mode), then ioutil.ReadAll\nf, err := os.Open(\"./main.go\")\n//or open in a different mode: \n// f, err := os.Open..."
url: "https://hashnode.com/posts/go-cheatsheet-read-and-write-file/6081e5faff5fc65284a76de3"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Go Cheatsheet - Read & Write File](https://hn.0xbf.me/go-cheatsheet-read-and-write-file?utm_source=hashnode&utm_medium=feed)

Read & Write File Read File content 1, Use ioutil.ReadFile: content, err := ioutil.ReadFile("sample.txt") 2, Open file first (in read-only mode), then ioutil.ReadAll f, err := os.Open("./main.go") //or open in a different mode: // f, err := os.Open...

Apr 22, 2021 · 1 min read · hn.0xbf.me  
Read the article

-   [#go](https://hashnode.com/tag/go)

## Written by

[0xBF](https://hashnode.com/@0xbf)

@0xbf

  
[View profile](https://hashnode.com/@0xbf)

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
