The File Class

Alongside the FileInfo class, the System.IO namespace provides a home for a static class called File. Whereas one usually uses a FileInfo to pass around information about a file as an object, the File class provides a series of static methods that expose file system functionality. In fact, some of FileInfo’s instance methods simply call into some of the static methods provided on file.

A first set of methods that deal with files on a wholesale basis is omitted from our discussion here because we’ve seen similar methods like Delete on FileInfo. Instead, we focus on methods that provide access to the contents of a file, which brings us to the concept of readers and writers quite directly.

Note: Directory Versus DirectoryInfo

As ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.