simple file writing example in google go (golang)

package main

import (
	"fmt"
	"io"
	"os"
)

func main() {

	filename := "test.txt"

	fmt.Println("writing: " + filename)
	f, err := os.Create(filename)
	if err != nil {
		fmt.Println(err)
	}
	n, err := io.WriteString(f, "blahblahblah")
	if err != nil {
		fmt.Println(n, err)
	}
	f.Close()
}

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>