-
Book Overview & Buying
-
Table Of Contents
Practical Systems Programming in Go
By :
Writing files is a fundamental operation in Go that allows programs to store data permanently on disk. Whether you need to save configuration settings, generate reports, or log application activity, the Go standard library provides straightforward and flexible tools for writing data to files. By choosing the right file-opening modes, you can control whether you overwrite existing content, append new data, or create files only if they do not already exist. Once you have a file handle, you can write data with methods such as f.Write(), which accepts a byte slice, or f.WriteString(), which accepts a string directly. For more efficient output, the bufio.NewWriter() type can wrap a file handle and perform buffer writes before flushing them with w.Flush(). Once you understand the basics of writing files in Go, the next step is to handle situations where you want to add new data to an existing file without overwriting its current contents. So, to kick things off, let's see...