In the last chapter, you learned how to deal with errors and logging. In this chapter, we are going to see recipes for working with files and directories in the Go language. You will also learn about parsing and using various formats such a XML, YAML, and JSON. This chapter will cover the following topics:
- Checking the existence of a file
- Reading the entire content of a text file
- Writing to a file
- Creating temporary files
- Counting lines in a file
- Reading a particular line in a file
- Comparing the contents of two files
- Deleting a file
- Copying or moving a file
- Renaming files
- Deleting a directory and its contents
- Listing all the files under a directory