After the C # FileStream StreamReader to read TXT delete the last line of data

Description:

 File_DownLoad = new FileStream(openf.FileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
                long Pos = 0;
                int Value;
                var Length = File_DownLoad.Length;
                bool HasText = false;
                do
                {
                       Pos--;
                        File_DownLoad.Seek(Pos, System.IO.SeekOrigin.End);
                        
                         //Delete_File_Lines.Write();

                        Value = File_DownLoad.ReadByte();
                        if (Value == 0xd || Value == 0xa)
                       {
                           if (HasText) break;
                       }
                        else
                             HasText = true;
                  } while (Length + Pos > 0);

                  File_DownLoad.SetLength(Length + Pos);

                  File_DownLoad.Seek (0, System.IO.SeekOrigin.Begin); // delete the last line read from the first line

 

Original code from the "Baidu know", the code really works, has solved the problem you're trying to solve,

Original link: https://zhidao.baidu.com/question/182251110861789444.html

Published 12 original articles · won praise 4 · Views 3035

Guess you like

Origin blog.csdn.net/weixin_42291376/article/details/104100986