MCPcopy Create free account
hub / github.com/Go-Learning-Land/Go-Learning-Archive / main

Function main

GolangBasics/GoByExample/061WriteFile.go:15–44  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13}
14
15func main() {
16
17 d1 := []byte("hello\ngo\n")
18 err := os.WriteFile("/tmp/dat1", d1, 0644)
19 check(err)
20
21 f, err := os.Create("/tmp/dat2")
22 check(err)
23
24 defer f.Close()
25
26 d2 := []byte{115, 111, 109, 101, 10}
27 n2, err := f.Write(d2)
28 check(err)
29 fmt.Printf("wrote %d bytes\n", n2)
30
31 n3, err := f.WriteString("writes\n")
32 check(err)
33 fmt.Printf("wrote %d bytes\n", n3)
34
35 f.Sync()
36
37 w := bufio.NewWriter(f)
38 n4, err := w.WriteString("buffered\n")
39 check(err)
40 fmt.Printf("wrote %d bytes\n", n4)
41
42 w.Flush()
43
44}

Callers

nothing calls this directly

Calls 4

CloseMethod · 0.80
PrintfMethod · 0.80
checkFunction · 0.70
WriteMethod · 0.45

Tested by

no test coverage detected