This chapter describes problems that work with files and directories. Some merely provide practice on working with files and the filesystem. You may find others to be a welcome addition to your programming toolkit. For example, some examples show how to search for duplicate files, load an image file without locking it, and save JPG images with different levels of compression.
Note that working with files and directories can be particularly dangerous for a program because that are many ways those operations can fail. For example, a directory might not exist, a file might be locked, a program might not have permission to read or write in a particular directory, or a disk drive may be corrupted. The examples in this chapter use try…catch blocks to protect themselves from unexpected file and directory errors but, to save space, I have not included...