C # File Processing Mechanism Overview

Source: Internet
Author: User

1. What is a stream? : A stream is used to transmit data between a carrier and a carrier. [The carrier is the carrier of data. For example, if the data is stored on the hard disk, the hard disk is the carrier, and the U disk is the carrier, and so on]

2. How does a stream transmit data? : Transfer of one byte and one byte. To put it bluntly, it refers to the transfer of byte arrays. [Byte array is a continuous memory space]

3. The object must be converted to a byte array before being transmitted using a stream.

4. Read File essence: string ----> encoding, serialization, and conversion of strings into byte arrays ---> byte [] ---> fs [FileStream] ---> File

5. essence of writing a file: file ---> fs [FileStream] ---> byte [] ---> decoding, deserialization, and conversion of byte arrays into strings ---> string

6. When a stream writes a file [Write], a new thread is automatically called to Write the file. Therefore, the buffer zone must be cleared after the file Write operation is completed. flush (); fs is an instance of FileStream, that is, ---> clear the unmanaged memory. Because a new file will be created during file write operations, and the Windows system will call the windows code for the non-hosted memory to exist. When fs. Flush () is called, the main thread waits for the write from the thread to finish, which is equivalent to calling EndInvoke (). It automatically implements the IDisposable interface to release the unmanaged memory.

7. garbled characters may occur when reading files because ---> the encoder does not use the same character set. For example: UTF8ENCODING, gb2312, UNICODE, etc.

8. stream classification:
Byte [] ----------> file stream ---------> File
Byte [] ---------> network stream ---------> Network
Byte [] ---------> memory stream ---------> Object
Byte [] ---------> cache stream ---------> another stream

Related Article

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.