开发者

The process can't access the file, because it is being used by another process [duplicate]

开发者 https://www.devze.com 2023-04-02 12:23 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Cant Access File because it is being used by another process
This question already has answers here: Closed 11 years ago.

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消