把字符串写入文件,最常用的功能
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main
import (
"fmt"
"io"
"os"
)
func main() {
filename := "test.txt"
file, err := os.Create(filename)
if err != nil {
fmt.Println(err)
}
fmt.Println(" Write to file : " + filename)
n, err := io.WriteString(file, " Hello World ! 你好")
if err != nil {
fmt.Println(n, err)
}
file.Close()
}
本文网址: https://golangnote.com/topic/204.html 转摘请注明来源