File Input Output in Go

Published on 28 April 2022 (Updated: 25 September 2022)

File Input Output in Go

Welcome to the File Input Output in Go page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

package main

import (
	"fmt"
	"io/ioutil"
	"log"
)

func read() (string, error) {
	contents, err := ioutil.ReadFile("output.txt")
	return string(contents), err
}

func write(contents string) error {
	return ioutil.WriteFile("output.txt", []byte(contents), 0644)
}

func main() {
	err := write("file contents")
	if err != nil {
		log.Fatal(err)
	}
	contents, err := read()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(contents)
}

File Input Output in Go was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.