c#窗体程序中实现循环写入保存文件问题
using System.Data;using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using
namespace sx
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 3; i++)
{
FileStream message = new FileStream("c:\\student.txt", FileMode.Create, FileAccess.Write);
StreamWriter text = new StreamWriter(message);
text.WriteLine(textBox1);
text.WriteLine(textBox2);
text.WriteLine(textBox3);
text.Close();
message.Close();
}
MessageBox.Show("保存成功");
}
private void button2_Click(object sender, EventArgs e)
{
FileStream message = new FileStream("c:\\student.txt", FileMode.Create, FileAccess.Write);
message.SetLength(0);
}
private void button3_Click(object sender, EventArgs e)
{
Close();
}
}
}
如上代码,试了几次for循环,不成功,还请大神指教。谢谢了。