标题:c#窗体程序中实现循环写入保存文件问题
只看楼主
花间酒
Rank: 2
等 级:论坛游民
帖 子:13
专家分:24
注 册:2017-4-4
结帖率:100%
已结贴  问题点数:10 回复次数:1 
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循环,不成功,还请大神指教。谢谢了。
搜索更多相关主题的帖子: 循环 using System Text message 
2017-09-12 11:23
jygyt
Rank: 2
等 级:论坛游民
帖 子:1
专家分:10
注 册:2016-11-16
得分:10 
FileStream message = new FileStream("c:\\student.txt", FileMode.Create, FileAccess.Write);
StreamWriter text = new StreamWriter(message);
text.Close();
message.Close();
你把这几句写在循环外面就行了
2017-09-12 15:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-480633-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047577 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved