FileStream seems to find an unexisting file

心已入冬 提交于 2020-01-17 04:43:05

问题


I have this code:

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;
}

I checked the ApplicationPath with the MessageBox.Show(); as you can see, go there and delete the file, re-launch the app, and it still reads the previous line . I uninstall the app re-install and still seems to find the file and read the same line I have entered in the very first installation. I searched windows, the whole C drive, there is no mail.txt and it still finds the mail.txt and reads the line (a email address, used to identify the user)

What can it be? aliens?


回答1:


Firstly, which code route does the program take? The one where the file is created, or the one where the existing file is read?

Try placing a breakpoint just before the existance of the file is checked and then go and check at that point if the file exists or not.




回答2:


Do you have any code elsewhere that creates and writes the file, as part of the application startup?

Otherwise, its definitely aliens.



来源:https://stackoverflow.com/questions/1887318/filestream-seems-to-find-an-unexisting-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!