#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