see comments for resolution--file was in wrong place
I've searched for an answer all over the place, but I haven't been able to find one. This is really frustrating to me because I've never had this much trouble reading from a file with any other programming language.
I'm trying to extract usernames and passwords from a text file for a basic instant messaging program. I'm not going to post all the code--it's too long, and it more than likely isn't relevant since the text file is being read at the very beginning of the program.
Here's the contents of the text file ("users.ul") I'm trying to read from:
admin.password
billy.bob
sally.sal
Here is the code that reads from the text file:
users = new Dictionary<string, User>();
System.Console.WriteLine("users.ul exists: " + File.Exists("users.ul"));
// Check the status of users.ul. If it exists, fill the user dictionary with its data.
if (File.Exists("users.ul"))
{
// Usernames are listed first in users.ul, and are followed by a period and then the password associated with that username.
StreamReader reader = new StreamReader("users.ul");
string line;
int count = 0;
while ((line = reader.ReadLine()) != null)
{
string[] splitted = line.Split('.');
string un = splitted[0].Trim();
string pass = splitted[1].Trim();
User u = new User(un, pass);
// Add the username and User object to the dictionary
users.Add(un, u);
count++;
}
System.Console.WriteLine("count: " + count);
reader.Close();
}
This is the output my code produces:
users.ul exists: True
count: 1
The only data added to the users dictionary is "admin" with the password "password". The other lines are ignored.
Please help me out here. My program is useless without multiple users. I've looked everywhere for a solution, including the other similar questions on this site. Never thought that reading from a file would cause me to waste so much time.