C # I/O action notes

Source: Internet
Author: User

1: Basic file I/O

1.1: Classes for file I/O

1.2: Classes used to read and write streams from the stream

1.3: Universal I/O Stream class

2: Universal I/O tasks

The following differences help clarify the differences between files and streams. A file is an ordered, named collection of bytes with permanent storage and a particular order. So, with regard to files, people often think of directory paths, disk storage, file and directory names, and so on. Instead, the stream provides a way to write bytes to the backing store and read bytes from the backing store, which can be one of several storage mediums. Just as there are a variety of backup stores outside of disk, there are multiple streams in addition to the file stream. For example, there are network flows, memory streams, and tape streams.

1: Basic file I/O

The abstract base class Stream supports reading and writing bytes. Stream is integrated with asynchronous support. Its default implementation defines synchronous reads and writes according to its corresponding asynchronous method, and vice versa.

All classes that represent the stream inherit from the stream class. The Stream class and its derived classes provide a general view of the data source and repository so that programmers do not have to understand the specifics of the operating system and the underlying device.

A stream involves three basic operations:

Can be read from the stream. Reading is a data transfer from a stream to a data structure, such as a byte array.

Can be written to a stream. Writes are data transfer from the source to the stream.

Streams can support lookups. Lookup is the query and modification of the current position within the convection.

Depending on the underlying data source or repository, the stream may support only a subset of these features. For example, Networkstreams does not support lookups. The CanRead, CanWrite, and CanSeek properties of the stream and its derived classes determine which operations are supported by different streams. 1.1: Classes for file I/O

Directory provides static methods for creating, moving, and enumerating directories and subdirectories. The DirectoryInfo class provides instance methods.

DirectoryInfo provides instance methods for creating, moving, and enumerating directories and subdirectories. The Directory class provides static methods.

DriveInfo provides an instance method for accessing information about a drive.

File provides static methods for creating, copying, deleting, moving, and opening files, and assists in creating FileStream. The FileInfo class provides instance methods.

FileInfo provides instance methods for creating, copying, deleting, moving, and opening files, and assists in creating FileStream. The File class provides a static method.

FileStream supports random access to files through its Seek method. By default, FileStream opens the file synchronously, but it also supports asynchronous operations. File contains static methods, while FileInfo contains instance methods.

FileSystemInfo is the abstract base class for FileInfo and DirectoryInfo.

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

Deflatestream provides methods and properties to compress and decompress streams using the Deflate algorithm.

GZipStream provides methods and properties to compress and decompress 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 that control serial port file resources.

File, FileInfo, DriveInfo, Path, Directory, and DirectoryInfo are sealed (NotInheritable in Microsoft Visual Basic) class. You can create new instances of these classes, but they cannot have derived classes. 1.2: Classes used to read and write streams from the stream

BinaryReader and BinaryWriter Read and write encoded strings and primitive data types in Streams.

StreamReader reads characters from the Streams by using Encoding to convert characters and bytes. StreamReader has a constructor that attempts to determine the correct Encoding of a given Stream, based on the existence of a preamble (such as a byte order mark) dedicated to Encoding.

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

StringReader reads characters from the Strings. StringReader allows you to use the same APIs to handle Strings, so your output can be String or Stream in any encoding.

StringWriter writes characters to Strings. StringWriter allows you to use the same APIs to handle Strings, so your output can be String or Stream in any encoding.

TextReader is the abstract base class for StreamReader and StringReader. The implementation of the abstract Stream class is used for byte input and output, while TextReader implementations are used for Unicode character output.

TextWriter is the abstract base class for StreamWriter and StringWriter. The implementation of the abstract Stream class is used for byte input and output, while TextWriter implementations are used for Unicode character output. 1.3: Universal I/O Stream class

BufferedStream is a stream that adds a buffer to another stream (for example, NetworkStream). (FileStream has buffers inside, MemoryStream does not need buffering.) BufferedStream can be structured around certain types of streams to improve read-write performance. A buffer is an in-memory byte block that is used to cache data, thereby reducing the number of calls to the operating system.

CryptoStream link the data stream to the cryptographic transformation. Although CryptoStream is derived from the Stream, it does not belong to the System.IO namespace, but to the System.Security.Cryptography namespace.

MemoryStream is a non buffered stream that can directly access its encapsulated data in memory. The stream has no backing store and can be used as a temporary buffer.

NetworkStream represents the Stream on a network connection. Although NetworkStream is derived from the Stream, it does not belong to the System.IO namespace, but to the System.Net.Sockets namespace.

2: Universal I/O tasks

The System.IO namespace provides several classes that allow you to perform various operations (such as read and write) on files, directories, and streams.

Address: http://msdn.microsoft.com/zh-cn/library/ms404278.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.