Hi guys, I want to create a file, but I don't understand the
fd parameter about the file descriptor.
I also want to append to the newly created file.
I found this code in the list:
package main
import ("fmt";"io";"io/ioutil";"os")
const file = "temp.txt"
func write(flag int, text string) {
f, err:=os.Open(file, flag, 0666)
if err != nil { fmt.Println(err); return }
n, err := io.WriteString(f, text)
if err != nil { fmt.Println(n, err); return }
f.Close()
data, err := ioutil.ReadFile(file)
if err != nil { fmt.Println(err); return }
fmt.Println(string(data))
}
func main() {
write(os.O_CREAT|os.O_TRUNC|os.O_RDWR, "new")
for i := 0; i < 2; i++ {
write(os.O_APPEND|os.O_RDWR, "|append")
}
}
Will that create the file also? (Only ask because I see the os.O_CREAT and imagine that that primitive will create the file if not present) </imagination>
f(t)