Go 最小 '写入文件' 示例
这是使用 Go 将字符串(在此示例中为 Hello World!)写入文件(在此示例中为 test.txt)的最小示例。
go_write_file_example.go
package main
import "io/ioutil"
func main() {
content := "Hello World!"
ioutil.WriteFile("test.txt", []byte(content), 0644)
}注意此示例:
- 以权限模式 0644创建文件,即只有所有者可以写入但其他人可以读取。
- 将文本编码为
UTF-8
Check out similar posts by category:
Go
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow