不确定为什么我已经使用using
和fs.Close()
和file.Close()
,但是第二次运行这些代码时仍然出现此错误。
using (FileStream fs = new FileStream(filePath,FileMode.Create))
{
using (StreamWriter file = new StreamWriter(fs))
{
// Display header
string header = string.Format("{0,-40} {1,-12} {2,-15} {3,-8}","Product Name","Unit Price","Quantity","Total");
file.WriteLine(header);
foreach (var item in shoppingCart2)
{
file.WriteLine("{0,item.ProductName,Utility.FormatAmount(item.UnitPrice),item.QuantityOrder,Utility.FormatAmount(item.TotalAmount));
table.AddRow(item.ProductName,Utility.FormatAmount(item.TotalAmount));
}
table.Options.EnableCount = false;
table.Write();
file.Close();
}
fs.Close();
}