The ability to handle common file I/O tasks is essential to all developers. The .NET Framework namespace, System.IO, exposes this functionality. By now, you should have a solid foothold in this namespace that will support you in your further explorations.
The following is a summary of some of the key points regarding common file I/O programming tasks:
DirectoryInfo and FileInfo classes contain specific instance methods related to a given directory or file. Whereas, the Directory and File classes pertain to static methods and are thus used in more generic cases.
Use the following four basic methods of the Directory class for manipulating directo- ries: Create, CreateSubdirectory, Delete, MoveTo, and Refresh.
Use the GetFiles method of Directory to access the files in a specific directory.
Use the following methods of FileInfo to manipulate files: Create, Delete, MoveTo, Refresh, CopyTo, Open, OpenRead, and OpenWrite.
The class, FileSystemWatcher, allows us to monitor the file system for new files, files being renamed, moved, and so on.
Use the FileStream object for all basic file reading and writing including asynchronous and binary.
To read files asynchronously, we call FileStream.BeginRead and pass the name of a procedure to receive callback notification when the operation is complete.
StreamWriter, StreamReader, BinaryWriter, and BinaryReader all provide additional, more advanced file streaming functionality.
ReadByte and WriteByte are the primary methods used for reading and writing binary data.