跳至主要内容

[pkg] io

io @ golang

  • func Copy: func Copy(dst Writer, src Reader) (written int64, err error)

寫檔案 os.WriteFile

os.WriteFile(<filename>, <data>, <permission>)

type user struct {
Username string `json:"username"`
Password string `json:"password"`
}

func main() {
u := user{
Username: "aaron.chen",
Password: "12345678",
}

data, _ := json.Marshal(u)
fmt.Println(string(data))
os.WriteFile("filename.json", data, 0644)
}