返回顶部

收藏

Golang下gb2312转UTF8并输出到文件

更多
package main

import (
    iconv "github.com/djimenez/iconv-go"
    "io/ioutil"
    "log"
    "net/http"
)

func main() {
    log.SetFlags(log.LstdFlags | log.Lshortfile)
    resp, err := http.Get("http://data.earthquake.cn/datashare/globeEarthquake_csn.html")
    if err != nil {
        log.Fatal(err)
    }

    defer resp.Body.Close()
    input, err := ioutil.ReadAll(resp.Body)
    out := make([]byte, len(input))
    out = out[:]
    iconv.Convert(input, out, "gb2312", "utf-8")
    ioutil.WriteFile("out.html", out, 0644)
}
//该片段来自于http://outofmemory.cn

标签:php,文件

收藏

0人收藏

支持

0

反对

0