Misunderstandings in the review of. NET IO

Source: Internet
Author: User

  #region  read the text of large files using StreamReader using  (StreamReader sr = new   string  txt = null                      while  (txt = Sr.                        ReadLine ())! = null  ) {  "  
     
      \r\n 
       ; }}   #endregion  

At first, I tried to solve the missing text of each line read "\ r \ n", so I used another method

 #regionA way to trouble//using (StreamReader sr = new StreamReader (OFD. FileName, Encoding.default))//{                //char[] buffer = new char[1024]; //int count = Sr. Read (buffer, 0, buffer.                Length); //String txt = new string (buffer); //This.textBox2.Text + = txt; //While (count = = buffer. Length)//    {                //        //Continue reading//count = Sr. Read (buffer, 0, buffer.                Length); //txt = new string (buffer. Take (count)).                Toarray<char> ()); //This.textBox2.Text + = txt; //    }                //}                 #endregion

The second method uses a buffer read so that no newline characters are lost, but each read to the end is repeated reads (the last text cannot fill the buffer to read repeatedly), causing the end of the article to be repeated, which makes me very annoyed, so I used a troublesome method, Intercept the length of each read in the buffer (I find that the length will not be counted, and the buffer will read repeatedly if it is not read).

Now think about it, maybe the first way is the simplest, don't think too complicated. As long as you add "\ r \ n" after each readline result, the ReadLine read of the method stops with the read line break.

Misunderstandings in the review of. NET IO

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.