dongzipu7517 2015-09-21 05:33
浏览 2845
已采纳

使用Golang将字节数组转换回文件

Is there a way to write a byte array to a file? I have the file name and file extension(like temp.xml).

  • 写回答

1条回答 默认 最新

  • dougan0529 2015-09-21 05:36
    关注

    Sounds like you just want the ioutil.WriteFile function from the standard library.

    https://golang.org/pkg/io/ioutil/#WriteFile

    It would look something like this:

    permissions := 0644 // or whatever you need
    byteArray := []byte("to be written to a file
    ")
    err := ioutil.WriteFile("file.txt", byteArray, permissions)
    if err != nil { 
        // handle error
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?