我一直在为一个大学项目做这个并且遇到了一个问题。我已设法从文件中加载多行,但无法将它们保存回文件。我可以将单个字符串保存到文件中,这是最后处理的字符串,但仅此而已。通过执行循环,我可能完全错了,但我想不出任何其他方法来做到这一点。保存文件部分的编码如下:
case "s":
case "8":
{
int savecount = 0;
string savestring = "";
//Clear the text file ready to be saved
using (FileStream fs = File.Create("billing.txt"))
{
}
while (savecount != CustomerCount)
{
using (StreamWriter save = new StreamWriter("billing.txt"))
{
//Create the string to save to the file
savestring = CustomerNumber[savecount] + ","
+ CustomerName[savecount] + ","
+ Address[savecount] + ","
+ RateScheme[savecount] + ","
+ PeakKWH[savecount] + ","
+ OffPeakKWH[savecount] + ","
+ StandardKWH[savecount];
Console.WriteLine(savestring);
save.WriteLine(savestring);
savecount++;
Console.ReadLine();
}
}
Console.WriteLine("All data saved successfully");
Console.ReadLine();
break;
}
不知道从这里去哪里。任何帮助,将不胜感激