Skip to content

Instantly share code, notes, and snippets.

@shouichi
Created February 4, 2015 04:30
Show Gist options
  • Save shouichi/e05d1ed0ff4bbd08b917 to your computer and use it in GitHub Desktop.
Save shouichi/e05d1ed0ff4bbd08b917 to your computer and use it in GitHub Desktop.
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