C# winform 如何实现在计算机指定路径保存和调取文件
入门级菜鸟请教,请大神说仔细点,最好能举个小例子。小弟感激不尽! 展开
2013-12-31
//引用 system.io
string path = "e://测试.txt";//这是路径
private void btnWrite_Click(object sender, EventArgs e)
{
if (txtWrite.Text != "")
{
using (FileStream fs = File.Open(path, FileMode.Create, FileAccess.Write))
{
using (StreamWriter sw = new StreamWriter(fs, Encoding.Default))
{
sw.WriteLine(txtWrite.Text);//把文本框里东西写进去
}
}
}
}
private void btnRead_Click(object sender, EventArgs e)
{
using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader sr = new StreamReader(fs, Encoding.Default))
{
while (!sr.EndOfStream)
{
txtRead.Text = sr.ReadLine();//读到txtread文本框
}
}
}
}
2013-12-31
2013-12-31