Ai
1 Star 0 Fork 0

田圃森/learn-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.go 661 Bytes
一键复制 编辑 原始数据 按行查看 历史
田圃森 提交于 2021-09-06 22:34 +08:00 . 一些示例
package main
import (
"io/ioutil"
"log"
)
func main() {
// Read the content
content, err := ioutil.ReadFile("hello.txt")
if err != nil {
log.Fatalf("error while reading the file. %v", err)
}
// new content
newText := []byte("\nAppended text.")
// The 3 dots after newText... is a variadic argument. In simple terms it will extract all the array elements.
// if a = [1,2,3,4]
// func (a...) => func (1, 2, 3, 4)
// append the content
content = append(content, newText...)
// overwrite the content of hello.txt
err = ioutil.WriteFile("hello.txt", content, 0777)
if err != nil {
log.Fatalf("error while writing the file. %v", err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/pustian/learn-go.git
git@gitee.com:pustian/learn-go.git
pustian
learn-go
learn-go
a7405e71a3e9

搜索帮助