Go program to read a text file character by character


Example

package main
 
import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)
 
func main() {
	filename := "test.txt"
 
	filebuffer, err := ioutil.ReadFile(filename)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	inputdata := string(filebuffer)
	data := bufio.NewScanner(strings.NewReader(inputdata))
	data.Split(bufio.ScanRunes)
 
	for data.Scan() {
		fmt.Print(data.Text())
	}
}
Most Helpful This Week