本文實(shí)例講述了C#簡單讀寫txt文件的方法。分享給大家供大家參考,具體如下:
//write txtStringBuilder builder = new StringBuilder();FileStream fs = new FileStream(saveFileName, FileMode.Create);StreamWriter sw = new StreamWriter(fs, Encoding.Default);for (int i = 0; i < ds.Tables[0].Rows.Count; i++){ DataRow dr = ds.Tables[0].Rows[i]; builder.AppendLine(dr["netsn"] + "," + dr["imei"]); //產(chǎn)品S/N號 + IMEI號}sw.Write(builder);sw.Close();fs.Close();if (System.IO.File.Exists(saveFileName)){ System.Diagnostics.Process.Start(saveFileName); //保存成功后打開此文件}//read txtstring[] allLines = File.ReadAllLines(filePath);更多關(guān)于C#相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《C#文件操作常用技巧匯總》、《C#程序設(shè)計(jì)之線程使用技巧總結(jié)》、《C#操作Excel技巧總結(jié)》、《C#中XML文件操作技巧匯總》、《C#常見控件用法教程》、《WinForm控件用法總結(jié)》、《C#數(shù)據(jù)結(jié)構(gòu)與算法教程》、《C#數(shù)組操作技巧總結(jié)》及《C#面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》
希望本文所述對大家C#程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選