源代码:
try
{
FileStream fsr = new FileStream(HtmlFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader sr = new StreamReader(fsr, Encoding.GetEncoding("gb2312"));
string str = sr.ReadToEnd();
sr.Close();
sr.Dispose();
fsr.Close();
//fsr.Dispose();
str = getTotalStr(str, xmlFile, xPath);
str = str.Replace("utf-8", "gb2312").Replace("UTF-8", "gb2312");
FileStream fsw = new FileStream(HtmlFilePath, FileMode.Open, FileAccess.Write, FileShare.ReadWrite);//此句引发异常
StreamWriter sw = new StreamWriter(fsw, Encoding.GetEncoding("gb2312"));
sw.Write(str);
sw.Close();
sw.Dispose();
fsw.Close();
fsw.Dispose();
}
catch (Exception e)
{
//e.Message=="文件xxxxx 正由另一进程使用,因此该进程无法访问该文件。";
}