Home > php教程 > php手册 > Golang下gb2312转UTF8并输出到文件

Golang下gb2312转UTF8并输出到文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:31:49
Original
3549 people have browsed it

找将字符串输出到文件的示例,搜到此段代码。 无 源码与演示: 源码出处 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("ht

找将字符串输出到文件的示例,搜到此段代码。

源码与演示:源码出处

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)
}
Copy after login
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
How to choose golang web mvc framework
From 1970-01-01 08:00:00
0
0
0
Is it necessary to use nginx when using golang?
From 1970-01-01 08:00:00
0
0
0
golang - vim plug-in to write go
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template