我想写一个代码,其中用户输入交货详细信息到文本框中并将文本添加到txt文件(记事本txt文件)。 这是我的尝试,我得到一个额外的行“,,”为什么它不会将文本从文本框添加到文本文件?将文本附加到文本文件的问题?
private void FrmDelivery_Load(object sender, EventArgs e)
{
if (theDelivery != null)
{
txtCustomerName.Text = theDelivery.customerName;
txtCustomerAddress.Text = theDelivery.customerAddress;
txtArrivalTime.Text = theDelivery.arrivalTime;
using (StreamWriter writer = new StreamWriter("visits.txt", true)) //true shows that text would be appended to file
{
writer.WriteLine(theDelivery.customerName + ", " + theDelivery.customerAddress + ", " + theDelivery.arrivalTime);
}
}
}
theDelivery是从类创建的对象交付 – littledevils326
写入文件的代码看起来很好,你甚至会得到'',',''。所以使用调试器并找出为什么'theDelivery.customerName'等是空的。 – weston
-1。请对齐你的标题和示例代码:你的标题询问如何附加到文件,但你的代码和问题的文本说,追加工作完美罚款,没有价值。 –