111,093
社区成员




StringBuilder sb = new StringBuilder();
sb.AppendLine($"首行");
foreach (Mapping item in MapData)
{
sb.AppendLine(item.ToString());
}
//储存
string DicFilePath = Path.Combine(BaseInfo, ProjectName, ProjectName + "_Dic.txt");
if (File.Exists(DicFilePath)) File.Delete(DicFilePath);
var fs = new FileStream(DicFilePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
using (StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("gb2312")))
{
sw.Write(sb.ToString());
}
fs.Close();
sb.Append($"首行");
foreach (Mapping item in MapData)
{
sb.AppendLine();
sb.Append(item.ToString());
}
StringBuilder sb = new StringBuilder();
sb.Append("123");
sb.AppendLine("456");
sb.Append("789");
结果:
123456
789sw.Write(sb.ToString().TrimEnd(new char[] { '\r', '\n' }) );
完美解决,谢谢两位老师~~
appendline行尾有换行,append没有
sb.AppendLine(item.ToString());
sb.Append(item.ToString());