Reading Files with a Buffer

This lesson explains how to use a buffer for reading purposes in Go.

We combine the techniques of buffered reading of a file and command-line flag parsing in the following example. If there are no arguments, what is typed in is shown again in the output. Arguments are treated as filenames, and when the files exist, their content is shown. Test it out with:

cat test.txt

Get hands-on with 1200+ tech skills courses.