Created
February 4, 2015 04:30
-
-
Save shouichi/e05d1ed0ff4bbd08b917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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