The realization of operating text File in C #
This article mainly explains "the implementation of operating text files in C#". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "the implementation of C# operating text files" bar!
How does C # manipulate text files? Let's start with the story:
Using System.IO; / / declaration control protected System.Web.UI.HtmlControls.HtmlTextArea txtValue
C # read text file for operating text file:
/ / main program FileStream fsInfo = new FileStream ("file path (within the project)", FileMode.Open, FileAccess.Read); StreamReader srInfo = new StreamReader (fsInfo, System.Text. Encoding.GetEncoding ("GB2312"); srInfo.BaseStream.Seek (0, SeekOrigin.Begin); txtValue.Value = ""; string strLine = srInfo.ReadInfo (); while (strLine! = null) {txtValue.Value + = strLine + "\ n"; strLine = srInfo.ReadLine ();} srInfo.Close ()
Write text file for C # operation text file:
/ / main program FileStream fsInfo = new FileStream (file path (within the project) ", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter swInfo = new StreamWriter (fsInfo); swInfo.Flush (); swInfo.BaseStream.Seek (0, SeekOrigin.Begin); swInfo.Write (txtValue.Value); swInfo.Flush (); swInfo.Close () At this point, I believe you have a deeper understanding of "the implementation of C# operating text files". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!