System.IO Namespace

The System.IO namespace contains types that allow reading and writing to files and data streams, and provides basic file and directory support.

Classes

File

Provides static methods for the creation, copying, deletion, moving, and opening of files, and helps in the creation of FileStream objects.

Directory

Exposes static methods for creating, moving, and enumerating through directories and subdirectories.

Path

Provides methods for processing directory strings in a cross-platform manner.

Stream

Represents a sequence of bytes that can be read from, written to, or both.

FileInfo

Provides instance methods for the creation, copying, deletion, moving, and opening of files.

DirectoryInfo

Provides instance methods for creating, moving, and enumerating through directories and subdirectories.

Enums

Sample Code

using System;
using System.IO;

class Program
{
    static void Main()
    {
        // Write text to a file
        File.WriteAllText(@"example.txt", "Hello, System.IO!");

        // Read the file back
        string content = File.ReadAllText(@"example.txt");
        Console.WriteLine(content);
    }
}