读写文件的问题!!!!!
本帖最后由 XiAnTianYiChuanMei 于 2013-09-11 19:17:54 编辑
FileStream fs = new FileStream(paht+@"\index.aspx", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamReader sr = new StreamReader(fs);
string mb= sr.ReadToEnd();
mb = mb.Replace("$$$$$$$$$$$$$", textBox2.Text);
StreamWriter sTmp = new StreamWriter(fs);
sTmp.WriteLine(mb);
fs.Close();
这样的话,文件没有修改
FileStream fs = new FileStream(paht+@"\index.aspx", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamReader sr = new StreamReader(fs);
string mb= sr.ReadToEnd();
mb = mb.Replace("$$$$$$$$$$$$$", textBox2.Text);
StreamWriter sTmp = new StreamWriter(paht + @"\index.aspx", false, Encoding.UTF8);
sTmp.WriteLine(mb);
fs.Close();
这样的话,又报错
文件“paht+@"\index.aspx"正由另一进程使用,因此该进程无法访问此文件。
怎么做,,不会了
------解决方案--------------------FileStream fs = new FileStream(@"test.txt", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);