Classes Used for Reading from and Writing to Streams



BinaryReader and BinaryWriter read and write encoded strings and primitive data types from and to Streams.

StreamReader reads characters from Streams, using Encoding to convert characters to and from bytes. StreamReader has a constructor that attempts to ascertain what the correct Encoding for a given Stream is, based on the presence of an Encoding-specific preamble, such as a byte order mark.

StreamWriter writes characters to Streams, using Encoding to convert characters to bytes.

StringReader reads characters from Strings. StringReader allows you to treat Strings with the same API, so your output can be either a Stream in any encoding or a String.

StringWriter writes characters to Strings. StringWriter allows you to treat Strings with the same API, so your output can be either a Stream in any encoding or a String.

TextReader is the abstract base class for StreamReader and StringReader. While the implementations of the abstract Stream class are designed for byte input and output, the implementations of TextReader are designed for Unicode character output.

TextWriter is the abstract base class for StreamWriter and StringWriter. While the implementations of the abstract Stream class are designed for byte input and output, the implementations of TextWriter are designed for Unicode character input.

 


Классы, используемые для чтения и записи в поток

Классы BinaryReader и BinaryWriter производят чтение и запись кодированных строк и простых типов данных в потоки.

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

StreamWriter записывает символы в потоки, используя кодировку для преобразования символов в байты.

StringReader считывает символы из строк. StringReader позволяет интерпретировать строки одним и тем же API-интерфейсом, поэтому в качестве выходных данных может использоваться класс Stream в любой кодировке, либо класс String.

StringWriter записывает символы в строки. StringWriter позволяет интерпретировать строки одним и тем же API-интерфейсом, поэтому в качестве выходных данных может использоваться класс Stream в любой кодировке, либо класс String.

TextReader является абстрактным базовым классом для класса StringReader и класса StreamReader. В то время как реализации абстрактного класса Stream предназначены для побайтового ввода и вывода, реализации TextReader предназначены для вывода знаков в кодировке Unicode.

TextWriter является абстрактным базовым классом для класса StringWriter и класса StreamWriter. В то время как реализации абстрактного класса Stream предназначены для побайтового ввода и вывода, реализации TextWriter предназначены для ввода знаков в кодировке Unicode.

 


Common I/O Stream Classes

A BufferedStream is a Stream that adds buffering to another Stream such as a NetworkStream. (FileStream already has buffering internally, and a MemoryStream does not need buffering.) A BufferedStream can be composed around some types of streams in order to improve read and write performance. A buffer is a block of bytes in memory used to cache data, thereby reducing the number of calls to the operating system.

A CryptoStream links data streams to cryptographic transformations. Although CryptoStream derives from Stream, it is not part of the System.IO namespace, but is in the System.Security.Cryptography namespace.

A MemoryStream is a nonbuffered stream whose encapsulated data is directly accessible in memory. This stream has no backing store and might be useful as a temporary buffer.

A NetworkStream represents a Stream over a network connection. Although NetworkStream derives from Stream, it is not part of the System.IO namespace, but is in the System.Net.Sockets namespace.

I/O and Security

When using the classes in the System.IO namespace, operating system security requirements such as access control lists (ACLs) must be satisfied for access to be allowed. This requirement is in addition to any FileIOPermission requirements.

Note:
ACLs can be managed programmatically.
Caution:
Default security policy for the Internet and an intranet does not allow access to files. Therefore, do not use the regular nonisolated storage I/O classes if you are writing code that will be downloaded over the Internet. Use Isolated Storage instead.

 


Дата добавления: 2019-03-09; просмотров: 218; Мы поможем в написании вашей работы!

Поделиться с друзьями:






Мы поможем в написании ваших работ!