Convert gb2312 to UTF8 under Golang and output it to the file

Source: Internet
Author: User
Find an example of outputting a string to a file and find the code segment. No source code and Demonstration: source code packagemainimport (iconvgithub. comdjimeneziconv-runtime) funcmain () {log. SetFlags (log. LstdFlags | log. l1_file) resp, err: http. Get (ht)

Find an example of outputting a string to a file and find the code segment. No source code and demo: source code package mainimport (iconv "github.com/djimenez/iconv-go" "io/ioutil" "log" "net/http") func main () {log. setFlags (log. lstdFlags | log. lw.file) resp, err: = http. get ("ht

Find an example of outputting a string to a file and find the code segment. <无>

Source code and demo:Source code

package mainimport (    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)}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.