Possible Duplicate:
Cant Access File because it is being used by another process
using (StreamWriter _SelectedFile = File.CreateText(CConstant.m_TEMPFILEPATH))
{
_SelectedFile.WriteLine(CConstant.m_SaveF开发者_开发知识库ileDefaultDirectory);
_SelectedFile.WriteLine(CConstant.Tempfile_ECUSelected);
_SelectedFile.WriteLine(CConstant.Tempfile_inifile);
_SelectedFile.WriteLine(CConstant.Tempfile_mapfile);
_SelectedFile.Flush();
_SelectedFile.Close();
_SelectedFile.Dispose();
}
When running the code, the very first time when i run the code(There is no temp.txt file ) , it throws an exception "The process can't access the file, because it is being used by another process."Please suggest a solution and also what's wrong in writing the code this way?
Cant you create FileStream with FileMode.OpenOrCreate option? rather than File?
using (StreamWriter sw = new StreamWriter(CConstant.m_TEMPFILEPATH, true))
replace your code with the code of upper ,and test it, is also same result?
精彩评论