가능한 중복 텍스트를 쓸 수 없습니다 : 그하지만 난 텍스트 파일에 일부 데이터를 쓸 수없는 이유를 잘 모르겠어요
The file is being used by another process, I must close it? How?나는 텍스트 파일로
. 나는 이렇게하고있다 :
private void CreateLastOpenFile()
{
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
if (!File.Exists(file))
{
FileStream newFile = File.Create(file);
newFile.Close();
}
using (StreamWriter lastOpenedFile = new StreamWriter(file))
{
lastOpenedFile.WriteLine(filePath);
}
}
내가 올바르게하고 있는가? 디렉토리가 있는지 확인해야 하는가? 파일이 있다면? 적절한 방법은 무엇입니까? MSDN에서 예제를 사용하고 있었지만 어떻게해야할지 모르겠습니다.
은 file/filePath를 예상대로 사용하고 있는지 확인합니다. 그것은 당신이 그 (것)들을 거꾸로 가지고있는 것처럼 보인다. – AlanFoster
당신이 이미 시작한 스레드의 답변을 보라. - http://stackoverflow.com/questions/8698879/the-file-is-being-used-by-another-process- i-must-close-it-how/8698914 # 8698914 – evilone