응용 프로그램 디렉토리에서 TXT 파일을 검사하는 WinForms 응용 프로그램이 있습니다. 단 한 줄 (사용자의 이메일) 또는 없음이 있습니다. 코드는 다음과 같습니다 :WinForms에서 FileStream의 이상한 동작
public static string GetUserEmail()
{
string path = Application.StartupPath + "\\mail.txt";
MessageBox.Show(path);
string adres = String.Empty;
if (File.Exists(path))
{
using (StreamReader sr = new StreamReader(path))
{
adres = sr.ReadLine();
}
}
else
{
using (FileStream fs = File.Create(path))
{
using (StreamReader sr = new StreamReader(path))
{
adres = sr.ReadLine();
}
}
}
MessageBox.Show(adres);
return adres;
}
이것은 정말 이상한 행동을 제외하고는 작동합니다. 프로그램을 제거하고 다시 설치하면 여전히 파일을 찾고 이전 전자 메일을 읽습니다. 나는 ApplicationDirectory를 검사했다. 그런 파일, 검색된 Windows, 전체 C 드라이브가 없다. no mail.txt가 있지만 처음 설치시 입력 한 메일 주소를 찾아서 읽는다. 모든 도움을 미리 감사드립니다.
중복 : http://stackoverflow.com/questions/1887318/filestream-seems-to-find-an-unexisting-file –