1 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
操作系統(tǒng)。寫(xiě)文件可以處理 和 函數(shù)的等效功能:WriteBytes
WriteString
// func WriteBytes(filepath string, bytes []byte) (err error)
err = os.WriteFile("testdata/hello", []byte("Hello, Gophers!"), 0666)
// func WriteString(filepath string, text string) (err error)
text := "Hello, Gophers!"
err = os.WriteFile("testdata/hello", []byte(text), 0666)
并與字符串組合。加盟可以處理:WriteLines
//func WriteLines(filepath string, lines []string) (err error)
lines := []string{"hello", "gophers!"}
err = os.WriteFile("testdata/hello", []byte(strings.Join(lines, "\n")), 0666)
- 1 回答
- 0 關(guān)注
- 100 瀏覽
添加回答
舉報(bào)