static object RecordLock = new object();
public static void SavePositionRecord(string _Name,int _OldValue,int _NewValue)
{
lock (RecordLock)
{
string mFilePath = "D:\\" + "电气坐标设置记录\\" + DateTime.Now.ToString("yyyy-MM-dd_HH_mm_ss") + ".csv";
if (!Directory.Exists("D:\\" + "电气坐标设置记录"))
{
Directory.CreateDirectory("D:\\" + "电气坐标设置记录");
}
try
{
if (!File.Exists(mFilePath))
{
//关键是这句话,可以解决中文乱码的问题
System.IO.File.WriteAllBytes(mFilePath, new byte[] { 0xEF, 0xBB, 0xBF });
System.IO.File.AppendAllText(mFilePath, "时间,坐标名称,修改前数值,修改后数值" + Environment.NewLine, Encoding.UTF8);
}
System.IO.File.AppendAllText(mFilePath, DateTime.Now.ToString() + "," + _Name + "," + _OldValue + "," + _NewValue + Environment.NewLine, Encoding.UTF8);
LdrLog("电气坐标设置记录|" + _Name + ":" + _OldValue + "->" + _NewValue);
}
catch (Exception ex)
{
LdrLog("保存文件失败:" + ex.Message);
}
}
}
解决CSV乱码
于 2023-02-17 14:58:13 首次发布