Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The realization of operating text File in C #

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report