2009-12-11 4 views
0

응용 프로그램 디렉토리에서 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가 있지만 처음 설치시 입력 한 메일 주소를 찾아서 읽는다. 모든 도움을 미리 감사드립니다.

+0

중복 : http://stackoverflow.com/questions/1887318/filestream-seems-to-find-an-unexisting-file –

답변

0

우선, 당신은 Application.Startup을 사용하고 있습니다. 실행 파일이있는 경로가 반환됩니다. 따라서 다른 위치로 파일을 보는 것에 대한 의문은 없습니다. C 드라이브 전체를 검색했다고 말하면서 정말 이상한 문제입니다. Windows Vista 및 Win 7에서 비슷한 문제가 발생했습니다.이 두 가지 운영 체제에서는 때때로 "SysWow"폴더에도 파일이 복사됩니다.