0

我有这个代码:

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

我用 MessageBox.Show(); 检查了 ApplicationPath 如您所见,去那里删除文件,重新启动应用程序,它仍然会读取上一行。我卸载应用程序重新安装,似乎仍然找到文件并阅读我在第一次安装时输入的同一行。我搜索了windows,整个C盘,没有mail.txt,它仍然找到mail.txt并读取该行(电子邮件地址,用于识别用户)

会是什么?外星人?

4

2 回答 2

1

首先,程序走哪条代码路线?创建文件的位置,还是读取现有文件的位置?

尝试在检查文件是否存在之前放置一个断点,然后在该点检查文件是否存在。

于 2009-12-11T11:28:43.550 回答
0

作为应用程序启动的一部分,您在其他地方是否有任何代码可以创建和写入文件?

否则,它绝对是外星人。

于 2009-12-11T11:02:41.980 回答