Free mag vol1 | Page 808

CHAPTER 20  FILE I/O AND OBJECT SERIALIZATION Directory DirectoryInfo You use these classes to manipulate a machine’s directory structure. The Directory type exposes functionality using static members, while the DirectoryInfo type exposes similar functionality from a valid object reference. DriveInfo This class provides detailed information regarding the drives that a given machine uses. File FileInfo You use these classes to manipulate a machine’s set of files. The File type exposes functionality using static members, while the FileInfo type exposes similar functionality from a valid object reference. FileStream This class gives you random file access (e.g., seeking capabilities) with data represented as a stream of bytes. FileSystemWatcher This class allows you to monitor the modification of external files in a specified directory. MemoryStream This class provides random access to streamed data stored in memory rather than in a physical file. Path This class performs operations on System.String types that contain file or directory path information in a platform-neutral manner. StreamWriter StreamReader You use these classes to store (and retrieve) textual information to (or from) a file. These types do not support random file access. StringWriter StringReader Like the StreamReader/StreamWriter classes, these classes also work with textual information. However, the underlying storage is a string buffer rather than a physical file. In addition to these concrete class types, System.IO defines a number of enumerations, as well as a set of abstract classes (e.g., Stream, TextReader, and TextWriter), that define a shared polymorphic interface to all descendants. You will read about many of these types in this chapter. The Directory(Info) and File(Info) Types System.IO provides four classes that allow you to manipulate individual files, as well as interact with a machine’s directory structure. The first two types, Directory and File, expose creation, deletion, copying, and moving operations using various static members. The closely related FileInfo and DirectoryInfo types expose similar functionality as instance-level methods (therefore, you must allocate them with the new keyword). In Figure 20-1, the Directory and File classes directly extend System.Object, while DirectoryInfo and FileInfo derive from the abstract FileSystemInfo type. 754