golang 写文件

package main

import (
    "bufio"
    "fmt"
    "io"
    "os"
)

func main() {     

    fil, err := os.OpenFile("C:/Documents and Settings/xxx/Desktop/tax.txt", os.O_RDWR|os.O_APPEND, 0420)
    if err != nil {
        fmt.Printf("Error: %s\n", err)
        return
    }
    defer fil.Close()
    fil.WriteString("Hello World!\n")

}

 

===============io WriteString==================

package main

import (
    "fmt"
    "io"
    "os"
)

func main() {
    writer, _ := os.OpenFile("C:/Documents and Settings/xxxx/Desktop/Copy of change-sub/b.md", os.O_RDWR|os.O_APPEND, 0420)
    data :=  data..xxxxxxx"
    n, err := io.WriteString(writer, data)
    if err != nil {
        fmt.Println("error write", n, "byte")
    }
    defer writer.Close()
}

 

本文来自:博客园

感谢作者:rojas

查看原文:golang 写文件

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。