Chapter 31. System.IO
The System.IO types serve as the primary means for
stream-oriented I/O—files, principally, although the abstract types
defined here serve as base classes for other forms of I/O, such as the XML
stack in System.Xml. The System.IO
namespace is shown in Figure 31-1 and Figure 31-2.
The System.IO namespace can be seen as two
distinct partitions: a set of utility types for using and working with the
local machine’s filesystem, and a protocol stack for working with bytestream-oriented
input and output. The former partition is the collection of classes such as
Directory and
FileSystemWatcher,
whereas the latter partition is the set of Stream
and Reader/Writer types.
The Stream types in
System.IO follow a basic object
model, similar to the I/O model used by the
C/C++ runtime library: all serial byte access is a stream, and
there are different sources and sinks for this serialized byte
data. In the System.IO package, this is represented
directly by the abstract base type Stream; its
concrete subtypes represent the actual I/O access:
FileStream
represents I/O to a file, and MemoryStream represents I/O to
a literal array of bytes (whose size is dynamically managed) in memory.
Other packages within the .NET Framework Class Library offer up their own
Stream-derived types. For example, in the System.Net
namespace, socket connections and HTTP responses are offered up as
Stream-derived types, giving .NET programmers the ability to treat any sort of input or output data ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access