User Program Communication

Write to FIle in Go

Used to create and write characters to a file.

//error is output if an error is raised
err = ioutil.WriteFile("outputFile.txt", data, permission) //assuming ioutil is written


Data is written to a file in a slice of bytes. File permission is the code which specifies the read/write access permissions of the file (ex. 0777, 0644).

package main

import (

func main() {
    var name string
    name = "Anthony"
    err = ioutil.WriteFile("name.txt", []byte(name), 0644) 

See Also

ioutil - The Go Programming Language

Add to Slack

< Read from Text File   |   Import Libraries >

© 2019 SyntaxDB. All Rights Reserved.