Answer the question
In order to leave comments, you need to log in
How to write an array of bytes to a file in golang?
Tried to do so
permissions := 0644 // or whatever you need
byteArray := []byte("to be written to a file\n")
err := ioutil.WriteFile("file.txt", byteArray, permissions)
if err != nil {
// handle error
}
./main.go:192:26: cannot use permissions (type int) as type os.FileMode in argument to ioutil.WriteFile
Answer the question
In order to leave comments, you need to log in
You need to cast permissions to type os.FileMode
permissions := 0644 // or whatever you need
byteArray := []byte("to be written to a file\n")
err := ioutil.WriteFile("file.txt", byteArray, os.FileMode(permissions))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question