【问题标题】:How to write multiple lines into a text file using golang如何使用 golang 将多行写入文本文件
【发布时间】:2022-01-28 03:46:27
【问题描述】:
        for {
            if resp.StatusCode == 200 {
                ...   
                break
            } else {
                data := fmt.Sprintf("[" + time.Now().Format("15:04:05") +"] " + strconv.Itoa(resp.StatusCode) + string(body) + "\n")
                file, err := os.Open("assets/errors.txt")
                if err != nil {
                    fmt.Println(err)
                }

                write := bufio.NewWriter(file)
                write.WriteString(data)
                write.Flush()
            }

【问题讨论】:

for { ... }os.OpenWriteString

标签: go