Introduction
File input and output (File I/O) are an important programming task that enables your applications to persist, retrieve, and exchange application data. In this module, you learn how to manage text files in C#, including how to create, read, write, and delete local text files and directories using classes in the System.IO namespace. You also learn how to work with structured and unstructured data types, and how to use common text file formats.
Imagine you're signed up to help a non-profit company with a software project. Before the project kicks off, you decide to update your programming skills by developing a banking app. To practice your file management skills, you plan to implement file input and output operations within the app's Program.cs file. You plan to work you way through some basic directory and file management tasks and then finish up with more advanced tasks like storing and retrieving bank transactions.
The topics covered in this module include:
- Get started with file input and output.
- Manage local directories, files, and paths.
- Read and write text files using the
StreamReaderandStreamWriterclasses. - Control file access using the
FileStreamclass. - Examine the
BinaryReaderandBinaryWriterclasses.
After completing this module, you're able to:
- Describe common file I/O operations, the difference between structured and unstructured data, common text file formats, and classes in the
System.IOnamespace. - Use the
Path,Directory, andFileclasses to create, copy, move, delete, and enumerate local text files and directories. - Implement file I/O operations using the
StreamReaderandStreamWriterclasses and CSV files. - Control file access using the
FileStreamclass. - Read and write binary files using the
BinaryReaderandBinaryWriterclasses. - Store and retrieve C# objects using file input and output operations.
By the end of this module, you have a solid understanding of file I/O operations and how to implement local file I/O in your projects. You're able to create, read, write, delete, and enumerate files and directories. You also have a better understanding of the different types of file formats and how to work with them effectively.