title: How can I implement String.split() in my login system?
body: <p>I have a text file called <strong>UserDetails.txt</strong> that I am trying to read from.</p>
  
  <p>Each line of the text file is as follows:</p>
  
  <blockquote>
    <p>John : Doe : Seattle : jd3 : 1234</p>
    
    <p>Jane : Doe : Olympia : jd4 : 5678</p>
    
    <p>Jerry : Doe : Redmond : jd5 : 9101</p>
    
    <p>And so on...</p>
  </blockquote>
  
  <p>Each line has the first name, last name, username, and password of the registered user by which I am trying to search for only the last two variables (username and password).</p>
  
  <pre><code>public class LoginFrame extends javax.swing.JFrame 
  {
  
  
  private static Scanner keyboard = new 
  Scanner(System.in);
  String username;
  String password;
  String filePath = "UserDetails.txt";
  
  public LoginFrame() {
  initComponents();
  }
  
  private void jButtonLoginActionPerformed(java.awt.event.ActionEvent evt) {                                             
  username = jTextFieldUsername.getText();
  password = jTextFieldPassword.getText();
  verifyLogin(username,password,filePath);
  }                                            
  
  public static void verifyLogin(String username, 
  String password, String filepath)
  {
  boolean match = false;
  String tempUserName = "";
  String tempPassword = "";
     try
     {
     keyboard = new Scanner(new 
     File(filepath));
     keyboard.useDelimiter("[:\n]");
  
     while(keyboard.hasNext() &amp;&amp; !match)
     {
         tempUserName = keyboard.next();
         tempPassword = keyboard.next();
  
         if(tempUserName.trim().equals(username.trim()) &amp;&amp; 
  tempPassword.trim().equals(password.trim()))
         {
             match = true;
         }
     }
     keyboard.close();
     System.out.print(match);
  }
  catch (Exception e)
  {
     System.out.print("Error");
  }
  }
  </code></pre>
  
  <p>This above code snippet is my original code by which I tried to use a delimiter to find the two specific values but it only seems to work if the username and password are the only two variables in the text file (with first and last names removed). </p>
  
  <p>I've been reading up on the String.split() method so that I can replace my original use of the delimiter. However, I'm still struggling with how I can apply it to my text file. Many of the examples online explain how one can convert an individual line into a String array (which in my example, would have the username at index 3 and password at index 4). This is where I'm confused though. How can I implement the String.split() method without having to manually input it for every specific line? (since there are 50 users in the text file). Would it be possible to implement it with the Scanner.nextLine() method?</p>