码迷,mamicode.com
首页 > Web开发 > 详细

2.8 decode encode

时间:2018-03-22 00:27:46      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:and   odi   mode   app   load   har   lang   file   coding   

cat /Users/zrd/Downloads/gostandardlib/Chapter02/Strings and Things/recipe08/win1250.txt
Gda?sk%

decode

package main

import (
    "io"
    "os"

    "golang.org/x/text/encoding/charmap"
)

func main() {

    f, err := os.OpenFile("out.txt", os.O_CREATE|os.O_RDWR, os.ModePerm|os.ModeAppend)
    if err != nil {
        panic(err)
    }
    defer f.Close()

    // Decode to unicode
    encoder := charmap.Windows1250.NewEncoder()
    writer := encoder.Writer(f)
    io.WriteString(writer, "Gdańsk")

}

/*

 */
package main

import (
    "io"
    "os"

    "golang.org/x/text/encoding/charmap"
)

func main() {

    f, err := os.OpenFile("out.txt", os.O_CREATE|os.O_RDWR, os.ModePerm|os.ModeAppend)
    if err != nil {
        panic(err)
    }
    defer f.Close()

    // Decode to unicode
    encoder := charmap.Windows1250.NewEncoder()
    writer := encoder.Writer(f)
    io.WriteString(writer, "Gdańsk")

}

2.8 decode encode

标签:and   odi   mode   app   load   har   lang   file   coding   

原文地址:https://www.cnblogs.com/zrdpy/p/8620674.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!