How to read file in Go

Here is the basic way to read a file in go using the ioutil go module. The ReadFile function requires only the file name. Then as output will give the content as a []byte and the error that will be nil if the file has successfully been read.


content, err := ioutil.ReadFile(FILE NAME)

Example: read a file with ioutil

package main
package main

import (

func main() {
	if content, err := ioutil.ReadFile("text_file.txt"); err == nil{

Other articles