logo
CSharp_Prog_Guide

Основы файлового ввода-вывода

Абстрактный базовый класс Stream поддерживает чтение и запись байтов. Класс Stream поддерживает асинхронный ввод и вывод. По умолчанию его реализация определяет операции синхронного чтения и записи на основе соответствующих им асинхронных методов, и наоборот.

Все классы, которые работают с потоками, являются производными от класса Stream. Класс Stream и его производные классы предоставляют способ просмотра источников данных и хранилищ объектов, изолируя программиста конкретных от специфических деталей операционной системы и базовых устройств.

При работе с потоками используются следующие основные операции:

В зависимости от лежащих в основе источника или хранилища данных потоки могут поддерживать только некоторые из этих возможностей. Например, NetworkStreams не поддерживает поиск. Свойства CanRead, CanWrite и CanSeek из Stream и его производных классов определяют операции, поддерживаемые различными потоками.

Classes Used for File I/O

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

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

DriveInfo provides instance methods for accessing information about a drive.

File provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of a FileStream.

FileInfo provides instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of a FileStream.

FileStream supports random access to files through its Seek method. FileStream opens files synchronously by default, but supports asynchronous operation as well.

FileSystemInfo is the abstract base class for FileInfo and DirectoryInfo.

Path provides methods and properties for processing directory strings in a cross-platform manner.

DeflateStream provides methods and properties for compressing and decompressing streams using the Deflate algorithm.

GZipStream provides methods and properties for compressing and decompressing streams. By default, this class uses the same algorithm as the DeflateStream class, but can be extended to use other compression formats.

SerialPort provides methods and properties for controlling a serial port file resource.

File, FileInfo, DriveInfo, Path, Directory, and DirectoryInfo are sealed classes. You can create new instances of these classes, but they cannot have derived classes.