The System.IO namespace contains types that allow synchronous and asynchronous reading from and writing to data streams and files.
The difference between a file and a stream is not always hard and fast, but the following distinctions are useful. A file is an ordered and named collection of a particular sequence of bytes having persistent storage. Therefore, with files, one thinks in terms of directory paths, disk storage, and file and directory names.
Streams provide a way to write and read bytes to and from a backing store that can be one of several storage mediums. Just as there are several backing stores other than disks, there are several kinds of streams other than file streams. For example, there are network, memory, and tape streams.
The abstract base class Stream integrates asynchronous support. Stream provides default implementations defining synchronous reads and writes in terms of their corresponding asynchronous methods, and visa versa.
All classes that represent streams inherit from the Stream class. The Stream class and its subclasses provide a generic view of data sources and repositories, isolating the programmer from the specific details of the operating system and underlying devices.
Streams involve these fundamental operations:
Depending on the underlying data source or repository, streams might support only some of these capabilities.
The System.IO classes provide the following functionality:
The Memory Stream class is a non-buffered stream whose encapsulated data is directly accessible in memory. This stream may reduce the need for temporary buffers and files in an application.
The FileAccess, FileMode, and FileShare enumerators define constants used by some of the FileStream and IsolatedStorageFileStream constructors and some of the File.Open overloaded methods. These constants affect the way in which the underlying file is created, opened, and shared.
The SeekOrigin enumerator is used by the Seek methods that are supported by streams. SeekOrigin defines constants that specify the point of entry for random access to files. These constants are used with byte offsets.
The FileAttributes and DirectoryAttributes enumerators are used by the File.Attributes and Directory.Attributes methods, respectively. FileAttributes and DirectoryAttributes define constants that represent Windows file attributes such as Archive, Hidden, and ReadOnly, which correspond to the attributes defined in WinNT.h.
All streams can support reading, writing, and seeking (random access).
The Stream, TextReader, and TextWriter classes are abstract classes. They cannot be directly instantiated, but are used only as base classes of other classes. Classes derived from Stream, TextReader, and TextWriter must include actual implementations of all inherited abstract methods and accessors by overriding them.
The Directory and File classes are sealed classes. These can be instantiated, but can have no subclasses.
All other documented System.IO members are public classes or enumerators.