User Program Communication

Write to FIle in Go

Used to create and write characters to a file.


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

Notes

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).


Example
package main

import (
"ioutil"
)

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

See Also
Documentation

ioutil - The Go Programming Language

Add to Slack

< Read from Text File   |   Import Libraries >

© 2019 SyntaxDB. All Rights Reserved.