Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing StreamReader.ReadLine in loop only reads one line from text file
    primarykey
    data
    text
    <p><strong>see comments for resolution--file was in wrong place</strong></p> <p>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.</p> <p>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.</p> <p>Here's the contents of the text file ("users.ul") I'm trying to read from:</p> <pre><code>admin.password billy.bob sally.sal </code></pre> <p>Here is the code that reads from the text file:</p> <pre><code>users = new Dictionary&lt;string, User&gt;(); 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(); } </code></pre> <p>This is the output my code produces:</p> <pre><code>users.ul exists: True count: 1 </code></pre> <p>The only data added to the users dictionary is "admin" with the password "password". The other lines are ignored.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload