在C#中怎样把Textbox中文本的文字写入一个.txt文件中?
3个回答
展开全部
导入System.IO
按钮单击事件:
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:/Documents and Settings/user/桌面/t.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(textBox1.Text);
sw.Close();
fs.Close();
}
按钮单击事件:
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:/Documents and Settings/user/桌面/t.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Write(textBox1.Text);
sw.Close();
fs.Close();
}
展开全部
using System.IO;
textBox1.Text = "111";
StreamWriter sw = new StreamWriter("1.txt",true);
sw.Write(textBox1.Text);
sw.WriteLine(textBox1.Text);
sw.Flush();
textBox1.Text = "111";
StreamWriter sw = new StreamWriter("1.txt",true);
sw.Write(textBox1.Text);
sw.WriteLine(textBox1.Text);
sw.Flush();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace save
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void save()
{
string filePath = @"D:\test.txt";
string txt = TextBox.Text;
File.WriteAllText(filePath, txt, Encoding.Default);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
save();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace save
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void save()
{
string filePath = @"D:\test.txt";
string txt = TextBox.Text;
File.WriteAllText(filePath, txt, Encoding.Default);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
save();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询