Golang : Write file with io.WriteString

Tags : golang write-file

Writing to a file in Golang is easy. There are couple of ways to do it. In this tutorial, we will show you how to write into plain text file.

 package main

 import (

 func main() {

 filename := "output.txt"

 file, err := os.Create(filename)

 if err != nil {

 fmt.Println(" Write to file : " + filename)

 n, err := io.WriteString(file, " Hello World !")

 if err != nil {
 fmt.Println(n, err)


Tags : golang write-file

By Adam Ng

IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.