mmoneyhome
mmoneyhome
2017-06-12 15:18
采纳率: 25%
浏览 960

关于WINCE 上 C#无法追加一行到文本文件上的问题

public bool AppendRecord(string fileName, SoilInfo.Record record)
{
FileStream fs = new FileStream(fileName, FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
if (sw == null)
{
MessageBox.Show("没有找到文件,或文件正在被占用", "错误");
return false;
}

    record.ProjectName +=  ",";
    record.SoilModelName +=  ",";
    record.Wet +=  ",";
    record.SoilDensity += ",";
    record.recordDescription +=  ",";
    record.language += "\r\n";
    string str = record.ProjectName + record.SoilModelName + record.Wet + record.SoilDensity + record.recordDescription + record.language;
    try
    {
        sw.WriteLine(str);

    }
    finally
    {
        sw.Dispose();
    }
    sw.Close();
    fs.Close();
    return true;
}

    代码如上所示
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • caozhy
    已采纳

    File.AppendAllText(文件名,内容)即可

    点赞 评论

相关推荐