日期:2014-05-20  浏览次数:21423 次

C#将数据写入记事本并且从记事本中读出
我想用C#将一行行数据(textbox)里边的写入到记事本,然后在把数据从记事本中读出来写到一个listbox中,请问应该怎样写,能否给出关键代码,急用,先谢谢了

------解决方案--------------------
友情一顶
为什么这么麻烦?
------解决方案--------------------
用StreamWriter和StreamReader,一个读,一个写,而且这两个类读写效率高!
------解决方案--------------------
用StreamWriter和StreamReader 我就用这种
------解决方案--------------------
C# code

using System.io;

fileStream fs=new fileStream ("yourtxt.txt",fileMode.Create);
StreamWirte sw=new StreamWirte (fs);
sw.WriteLine(textbox.Text);
sw.Close();
fs.Close();

------解决方案--------------------
楼上已经把代码展出来了!
------解决方案--------------------
C# code


using System.IO;

//写入
StreamWriter sw = new StreamWriter( @"C:\temp123.txt");
sw.WriteLine("----------------hello----------------");
sw.WriteLine("内容");
sw.WriteLine("----------------hello----------------");
sw.Flush();
sw.Close();

//读取
System.IO.StreamReader st;
st = new System.IO.StreamReader(@"C:\temp123.txt", System.Text.Encoding.UTF8);//UTF8为编码
this.textBox1.Text = st.ReadToEnd();

------解决方案--------------------
StreamWriter和StreamReader
------解决方案--------------------
探讨
C# code

using System.IO;

//写入
StreamWriter sw = new StreamWriter( @"C:\temp123.txt");
sw.WriteLine("----------------hello----------------");
sw.WriteLine("内容");
sw.WriteLine("----------------hello----------------");
sw.Flush();
sw.Close();

//读取
System.IO.StreamReader st;
st = new System.IO.StreamReader(@"C:\temp123.txt", System.Text.Encoding.UTF8);//UTF8为编码
this.textBo…

------解决方案--------------------
他们都把代码贴出来了,你google一下一大堆.
我也是用的StreamWriter和StreamReader
------解决方案--------------------
while (sr.EndOfStream == false)
{
string ss=sr.ReadLine(); 
this.listBox1.Items.add(ss);
}
------解决方案--------------------
探讨
用StreamWriter和StreamReader 我就用这种

------解决方案--------------------
探讨
while (sr.EndOfStream == false)
{
string ss=sr.ReadLine();
this.listBox1.Items.add(ss);
}

------解决方案--------------------
探讨
我现在要从文件里读取多行添加到listbox里边,我用StreamReader sr=new StreamReader(、、、、、)

string ss=sr.ReadLine(); this.listBox1.Items.add(ss),只能将一行数据插入到listbox中,请问应该怎样将所有的添加到listbox中

------解决方案--------------------
探讨
C# code

using System.IO;

//写入
StreamWriter sw = new StreamWriter( @"C:\temp123.txt");
sw.WriteLine("----------------hello----------------");
sw.WriteLine("内容");
sw.WriteLine("----------------hello----------------");
sw.Flush();
sw.Close();