Few things are more fundamental to developing applications than file I/O (input/output). A lot of file I/O happens behind the scenes. .NET applications, for example, are typically comprised of multiple DLL files, and the runtime handles when and how to load them. Configuration is often loaded from files. Applications may read text files and parse their contents into objects or transform them into other formats.
In this section, we’ll explore how to explicitly locate, read, and write files in code using .NET’s built-in libraries. Most of these APIs are available in the System.IO namespace, which is automatically included with implicit using statements.
In this chapter, you’ll create a lot of console applications with some boilerplate code that we used in previous chapters. We’ll save a lot of time if we create a custom dotnet new template with the code to handle command-line arguments. Let’s start by creating a new console application, using the commands from the following listing.