1. 程式人生 > >go 建立檔案並寫入字串

go 建立檔案並寫入字串

package main

import (
"fmt"
"os"
)

func main(){
        fileName := "test.pdf"
        dstFile,err := os.Create(fileName)
        if err != nil {
                fmt.Println(err.Error())
                return
        }
        defer dstFile.Close()
        s:="hello world"
        dstFile.WriteString(s+"\n")
}