在使用 sytem.IO 方法使用某个文本文件之前,我需要获取它的位置。我试图让一个应用程序在所有计算机上运行,但是当我在计算机之间切换时,它似乎将我的 D:驱动器内存笔更改为和 F:驱动器,因此位置发生了变化。这是我一直在尝试使用的:
baseLocation = Application.ExecutablePath;
string UsernameTXT = @PublicVariables.baseLocation + "//userName.txt"
StreamReader user_Login = new StreamReader(UsernameTXT);
string PasswordTXT = @PublicVariables.baseLocation + "//userPass.txt"
StreamReader pass_Login = new StreamReader(PasswordTXT);
while (pass_Login.Peek() != -1)
{
user = user_Login.ReadLine();
pass = pass_Login.ReadLine();
if ((user == textBox1.Text) && (pass == textBox2.Text))
{
MessageBox.Show("Login successful!",
"Success");
}
}
我知道这部分是错误的:
string UsernameTXT = @PublicVariables.baseLocation + "//userName.txt"
StreamReader user_Login = new StreamReader(UsernameTXT);
string PasswordTXT = @PublicVariables.baseLocation + "//userPass.txt"
StreamReader pass_Login = new StreamReader(PasswordTXT);
只是我不知道在那里使用什么。
任何帮助表示赞赏。