golang 编码转换 gbk

ziyouzhiqiu ·
请问下如何使用golang.org/x/text将gbk的中文转成utf8
#1
更多评论
@ anko ```go package main import ( "fmt" "io/ioutil" "os" "golang.org/x/text/transform" "golang.org/x/text/encoding/simplifiedchinese" ) func main() { f, err := os.Open("C:\\Users\\sherl\\Desktop\\11.txt") if err != nil { panic(err) } // 编码转换 utfReader := transform.NewReader(f, simplifiedchinese.GB18030.NewDecoder()) all, err := ioutil.ReadAll(utfReader) if err != nil { panic(err) } fmt.Printf("%s\n", all) } ```
#2
1楼 <a href="/user/anko" title="@anko">@anko</a> 看我回复
#3