直接 `new StreamWriter(path)` 默認**追加**模式,導致舊內容未清空;改用 `FileStream(FileMode.Create)` 再包裹 `StreamWriter` 雖能清空,但讀取時出現亂碼(編碼不一致)。
// .NET 4.0+ 直接覆蓋寫入,默認 UTF-8 無 BOM
System.IO.File.WriteAllText(filePath, content);
// 指定編碼(如 GB2312/UTF-8 with BOM)
System.IO.File.WriteAllText(filePath, content, Encoding.GetEncoding("gb2312"));
// 追加寫入
System.IO.File.AppendAllText(filePath, newLine, Encoding.UTF8);
// 讀取對應
string text = System.IO.File.ReadAllText(filePath, Encoding.UTF8);