System.IO Namespace

Provides types that allow reading and writing files and data streams, and types that handle file and directory manipulations. This namespace is fundamental for any application that needs to interact with the file system or manage data persistence.

Classes

  • File

    Provides static methods for creating, copying, deleting, moving, and opening files. Also provides methods for creating FileStreams.

  • Directory

    Provides static methods for the creation, moving, and enumeration of directories and subdirectories.

  • Path

    Provides properties and methods, useful for creating, manipulating, and converting between file and directory path strings. It isolates the logic of path manipulation from the operating system.

  • Stream

    Abstract base class and a delegate of synchronous and asynchronous I/O operations. It is the abstract base class for all streams in the .NET Framework.

  • FileInfo

    Provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in their creation, deletion, and opening. Allows for detailed querying of file properties.

  • DirectoryInfo

    Provides instance methods for the creation, moving, and enumeration of directories and subdirectories. Allows for detailed querying of directory properties.

  • StreamWriter

    Implements a TextWriter for writing characters to a stream in a particular encoding. Inherits from TextWriter.

    using System.IO;
    
    // ...
    
    using (StreamWriter writer = new StreamWriter("myFile.txt"))
    {
        writer.WriteLine("Hello, World!");
        writer.WriteLine("This is a test.");
    }
  • StreamReader

    Implements a TextReader for examining the byte-stream as Unicode text. Inherits from TextReader.

    using System.IO;
    
    // ...
    
    using (StreamReader reader = new StreamReader("myFile.txt"))
    {
        string line;
        while ((line = reader.ReadLine()) != null)
        {
            Console.WriteLine(line);
        }
    }

Interfaces

  • IDisposable

    Provides a mechanism for releasing unmanaged resources.

  • IAsyncResult

    Encapsulates all the information that is necessary to use an asynchronous operation. This is the base interface for all asynchronous operations.