Files are important components of our daily lives in the modern world.

Text files are useful for storing structured human-readable data without the use of external software or databases.

Thebufiopackage builds upon theio.Readerandio.Writerinterfaces, which are extensively used in the implementation of the majority of Gos standard packages.

Article cover design for Handling text files in Go

Thebufiopackage goes one step further by implementing buffering, making it useful for IO operations involving textual data.

To use thebufiopackage in your program, you should import it alongside other packages.

You probably heard when yougot started with Gothat it comes with everything you could possibly need as a programmer.

Output of program to read text from file

For direct communication with your operating system, there is a package calledosthat provides platform-independent functions.

Theosandbufiopackages make text file manipulation incredibly simple.

So, how do you manipulate files containing text in Go?

Output of program to read and write to text file

Another method to get the file is by using theOpenFile()function.

The next sample code is a continuation of the one to read a file.

In this example, data is written to the existingtestfile.txtusing theO_WRONLYandO_APPENDflags.

golang write operation