. NET IO: Byte stream

Source: Internet
Author: User

Using the Stream class to manage the byte stream

Using the FileStream class to manage file data

Using the MemoryStream class to manage memory data

Using the Bufferedsream class to improve flow performance

3.1FileStream

MemoryStream

Seek positioning, addressing

BufferedStream

3.2 Managing Application Data

Text, Stream, string, and binary data

Managing text data and strings

(1) TextReader Class (abstract class)

(2) TextWriter Class (abstract class)

Managing strings

Managing binary data with BinaryReader and Binarywrter

3.2.1.file Operations
       Really associated to a file            //streamreader to a text file: Read <--parent class: Stream            //streamwriter to text file: Write <--parent class: Stream            string file = @ "F:\text.txt";            FileStream fs = File.Open (File, filemode.openorcreate);            StreamWriter SW = new StreamWriter (fs);            Sw. WriteLine ("Now: {0},", DateTime.Now);            Sw. Flush ();            Sw. Close ();            StreamReader sr = new StreamReader (File.Open (File, FileMode.Open));            Console.WriteLine (Sr. ReadToEnd ());

3.2.2.string Manipulation
         In memory, string is manipulated as a file to              //stringreader to string: Read <--textreader            //stringwriter to string: Write <--textwiter            StringBuilder sb = new StringBuilder ();            StringWriter SWS = new StringWriter (SB);            SwS. WriteLine (123 + 321);            SwS. WriteLine (true);            StringReader SRR = new StringReader (sb.) ToString ());            Console.WriteLine (SRR. ReadToEnd ());

3.2.3.Binary Operations
        Binary            BinaryWriter bw = new BinaryWriter (File.Open (@ "F:\a.dat", FileMode.OpenOrCreate));            Bw. Write (true);            Bw. Write (' A ');            Bw. Write (123);            Bw. Flush ();            Bw. Close ();            Read in order            binaryreader br = new BinaryReader (File.Open (@ "F:\a.dat", FileMode.Open));            Console.WriteLine (Br. Readboolean ());    Corresponds to True            Console.WriteLine (Br. ReadChar ());       Corresponds to ' A '            Console.WriteLine (Br. ReadInt32 ());      Corresponds to 123

(GO). NET IO: Byte stream

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.