//write txt
StringBuilder 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"]); //产品S/N号 + IMEI号
}
sw.Write(builder);
sw.Close();
fs.Close();
if (System.IO.File.Exists(saveFileName))
{
System.Diagnostics.Process.Start(saveFileName); //保存成功后打开此文件
}
//read txt
string[] allLines = File.ReadAllLines(filePath);
c#读写txt文件
点赞
收藏