Csharp/C#教程:C#简单读写txt文件的方法分享

本文实例讲述了C#简单读写txt文件的方法。分享给大家供大家参考,具体如下:

//writetxt StringBuilderbuilder=newStringBuilder(); FileStreamfs=newFileStream(saveFileName,FileMode.Create); StreamWritersw=newStreamWriter(fs,Encoding.Default); for(inti=0;i<ds.Tables[0].Rows.Count;i++) { DataRowdr=ds.Tables[0].Rows[i]; builder.AppendLine(dr["netsn"]+","+dr["imei"]);//产品S/N号+IMEI号 } sw.Write(builder); sw.Close(); fs.Close(); if(System.IO.File.Exists(saveFileName)) { System.Diagnostics.Process.Start(saveFileName);//保存成功后打开此文件 } //readtxt string[]allLines=File.ReadAllLines(filePath);

更多关于C#相关内容感兴趣的读者可查看本站专题:《C#文件操作常用技巧汇总》、《C#程序设计之线程使用技巧上述就是C#学习教程:C#简单读写txt文件的方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/907417.html

(0)
上一篇 2021年10月24日
下一篇 2021年10月24日

精彩推荐