成都网站建设设计

将想法与焦点和您一起共享

C#操作文本文件实例浅析

C#操作文本文件是如何实现的呢?让我们开始讲述吧:

站在用户的角度思考问题,与客户深入沟通,找到邯郸网站设计与邯郸网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站制作、成都做网站、外贸营销网站建设、企业官网、英文网站、手机端网站、网站推广、域名注册、网页空间、企业邮箱。业务覆盖邯郸地区。

 
 
 
  1. using System.IO;  
  2.  
  3. //声明控件  
  4. protected System.Web.UI.HtmlControls.HtmlTextArea txtValue; 

C#操作文本文件之读取文本文件:

 
 
 
  1. //主程序  
  2. FileStream   fsInfo = new  FileStream(   
  3. "文件路径(在项目内的)", FileMode.Open, FileAccess.Read );  
  4. StreamReader  srInfo  =  new StreamReader(   
  5. fsInfo, System.Text. Encoding.GetEncoding( "GB2312" ) );  
  6. srInfo.BaseStream.Seek( 0, SeekOrigin.Begin );  
  7. txtValue.Value  = " ";  
  8. string strLine  = srInfo.ReadInfo();  
  9. while( strLine != null )  
  10. {  
  11. txtValue.Value  +=   strLine  + "\n";  
  12. strLine   =   srInfo.ReadLine();  
  13. }  
  14. srInfo.Close(); 

C#操作文本文件之写入文本文件:

 
 
 
  1. //主程序  
  2. FileStream fsInfo  = new FileStream(  
  3.  文件路径(在项目内的)", FileMode.OpenOrCreate, FileAccess.Write );  
  4. StreamWriter swInfo = new StreamWriter( fsInfo );  
  5. swInfo.Flush();  
  6. swInfo.BaseStream.Seek( 0, SeekOrigin.Begin );  
  7. swInfo.Write( txtValue.Value );  
  8.  
  9. swInfo.Flush();  
  10. swInfo.Close(); 

C#操作文本文件的基本实现内容就向你介绍到这里,希望对你了解和学习C#操作文本文件有所帮助。


网页标题:C#操作文本文件实例浅析
分享路径:https://chengdu.cdxwcx.cn/article/dhhjssc.html