I have a Go program to read a text file similar to the code below:
package main
import (
"bufio"
"log"
"os"
)
func main() {
file, err := os.Open("test.txt")
if err != nil {
log.Fatalf("failed opening file: %s", err)
}
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
var txtlines []string
for scanner.Scan() {
txtlines = append(txtlines, scanner.Text())
}
file.Close()
}
Playground: https://play.golang.org/p/cnDOEFaT0lr
The code works fine for all the text files except the files which have been encoded with UCS-2 little endian. How can I convert the file to UFT8 format to read it?
UCS-2 is a proper subset of UTF-16.
For example,
Playground: https://play.golang.org/p/3VombFxUNb1