title: Reading username and password from a text file and comparing them to textfields won't work eventhough they are the exact same
body: <p>I need to create a login/register app that stores and retrieves users info from a file(.txt). So I am comparing the username and password from my file with the username and password from my textfields and eventhough they are the exact same the programm still will not match them.</p>
  
  <p>It was working at some point but that was when I only had the <code>Login</code> class. After I finished the <code>Register</code> class it would not work eventhough I did not change anything in the <code>Login</code> class. I also tried to handwrite the txt just as I did the first time but no luck.</p>
  
  <p><strong><code>Login</code> class:</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.Scanner;
  
  class Login extends JFrame implements ActionListener {
  
      JButton SUBMIT;
      JPanel panel;
      JLabel label1, label2;
      final JTextField text1, text2;
  
      Login() {
          label1 = new JLabel();
          label1.setText("Username:");
          text1 = new JTextField(15);
  
          label2 = new JLabel();
          label2.setText("Password:");
          text2 = new JPasswordField(15);
  
          SUBMIT = new JButton("SUBMIT");
  
          panel = new JPanel(new GridLayout(3, 1));
          panel.add(label1);
          panel.add(text1);
          panel.add(label2);
          panel.add(text2);
          panel.add(SUBMIT);
          add(panel, BorderLayout.CENTER);
          SUBMIT.addActionListener(this);
          setTitle("LOGIN FORM");
      }
  
      public void actionPerformed(ActionEvent ae) {
          File loginf = new File("filename.txt");
  
          try {
              Scanner read = new Scanner(loginf);
              read.useDelimiter("\\n|,");
              boolean login = false;
              while (read.hasNext()) {
                  String user = read.next();
                  String pass = read.next();
                  String thisuser = text1.getText();
                  String thispass = text2.getText();
                  System.out.println(user + " " + pass);
                  System.out.println(thisuser + " " + thispass);
                  if (thisuser.equals(user) &amp;&amp; thispass.equals(pass)) {
                      System.out.println("OOOKKKK");
                      login = true;
                      break;
                  }
              }
              if (login) {
                  NextPage page = new NextPage();
                  page.setVisible(true);
                  JLabel label = new JLabel("Welcome:" + text1.getText());
                  page.getContentPane().add(label);
                  setVisible(false);
              } else {
                  JOptionPane.showMessageDialog(null, "Incorrect username or password");
                  text1.setText("");
                  text2.setText("");
              }
              read.close();
          } catch (FileNotFoundException qwerty) {
              JOptionPane.showMessageDialog(null, "Can't find a text file");
          }
      }
  
  }
  </code></pre>
  
  <p><strong>Parts of the <code>Register</code> class that I am using:</strong></p>
  
  <pre><code>ln95: FileWriter out = null;
  ln98: out = new FileWriter("filename.txt", true);
  
  
  ln149:out.write(username + "," + pass);
  ln150:out.write(System.getProperty("line.separator"));
  </code></pre>
  
  <p><strong>Output from login:</strong></p>
  
  <pre><code>student1 Student1
  student2 Student2    
  student2 Student2
  student2 Student2    
  student3 Student3
  student2 Student2
  </code></pre>