创建文件后未将文件关闭
string sTransLogFile = sTransLogPath + "\" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; if (!Directory.Exists(sTransLogPath)) Directory.CreateDirectory(sTransLogPath); if (!File.Exists(sTransLogFile)) File.Create(sTransLogFile).Close(); using (FileStream stream = new FileStream(sTransLogFile, FileMode.Append)) using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine($"BARCODE_NO:{sBarcodeNo}"); }