Skip to content

Instantly share code, notes, and snippets.

@shouichi
Created Feb 4, 2015
Embed
What would you like to do?
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/transform"
)
// Reads and prints ShiftJIS file.
func main() {
flag.Parse()
f, err := os.OpenFile(flag.Arg(0), os.O_RDONLY, 0600)
if err != nil {
log.Fatal(err)
}
defer f.Close()
r := transform.NewReader(f, japanese.ShiftJIS.NewDecoder())
b, err := ioutil.ReadAll(r)
if err != nil {
log.Fatal(err)
}
fmt.Print(string(b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment