-
Book Overview & Buying
-
Table Of Contents
Mastering Go - Third Edition
By :
In this section you will learn how to read plain text files, as well as using the /dev/random UNIX device, which offers you a way of getting random numbers.
The function for reading a file line by line is found in byLine.go and is named lineByLine(). The technique for reading a text file line by line is also used when reading a plain text file word by word as well as when reading a plain text file character by character because you usually process plain text files line by line. The presented utility prints every line that it reads, which makes it a simplified version of the cat(1) utility.
First, you create a new reader to the desired file using a call to bufio.NewReader(). Then, you use that reader with bufio.ReadString() in order to read the input file line by line. The trick is done by the parameter of bufio.ReadString(), which is a character that tells bufio.ReadString() to keep reading until that character is found...