使用c#中的Filestream概念将给定值保存在记事本中 [英] Save the given value in the notepad using Filestream concept in c#
本文介绍了使用c#中的Filestream概念将给定值保存在记事本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
海,
我有一个TextBox和Button.
如果我在该文本框中输入一些文本,然后单击按钮".
该文本将保存在新记事本中.
在此先感谢.
Hai,
I have one TextBox and Button.
If i enter Some text in that TextBox and then i click the Button.
That text are Save in the New Notepad.
Thanks in Advance.
推荐答案
这 [ ^ ]将为您提供帮助.
This[^] would help you out.
如果您打算将文本保存在记事本文件(即文本文件或扩展名为".txt"的文件)中,则可以很简单:
处理Button Click事件,并插入以下代码:
If you mean to save the text in a Notepad file (i.e. a text file, or one that has the extension ".txt") then it is pretty simple:
Handle the Button Click event, and insert the following code:
File.WriteAllText(@"C:\Temp\MyFile.txt", myButton.Text);
您不需要将流用于简单的事情!
You don''t need to use a stream for something that simple!
在按钮单击事件中编写此代码.
Write this code at button click event.
StreamWriter s=new StreamWriter(Application.StartupPath+"my.txt");
s.Write(textBox1.Text);
s.Close();
您必须包含System.IO命名空间才能访问IO操作.
You should have to include System.IO namespace to access the IO operaions.
这篇关于使用c#中的Filestream概念将给定值保存在记事本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文