title: Creating registration program in java?
body: <p>I have a simple problem.</p>
  
  <p>I'm  trying to create a registration program using text files in java.</p>
  
  <p>I wrote some code to do registration but at first my program should check if username is exists in text file or not.</p>
  
  <p>If username is exists then the program asks user to enter new one.</p>
  
  <p>But there is some error in my code i don't know, it is not checking if username exists or not.</p>
  
  <p>here is my code:</p>
  
  <pre><code>                System.out.println("Registration Page");
                  System.out.println("NOTE: your username is a unique one so it cannot be changed.");
                  System.out.printf("Username: ");
                  String user = input.next();
                  System.out.printf("Password: ");
                  String pass = input.next();
                  System.out.printf("Confirm Password: ");
                  String conf = input.next();
                  int length = pass.length();
                  int passInt = Integer.parseInt(pass);
                  int confInt = Integer.parseInt(conf);
                  if(length &lt; 6)
                      System.out.println("Too short password, password must be 6 characters or more");
                  else
                  {
                  if(passInt == confInt)
                  {
                  Scanner z = null;
                  try{
                  z = new Scanner(new File("C:\\Users\\فاطمة\\Downloads\\accounts.txt"));
                  boolean checkname = false;
                  while(z.hasNext())
                  {
                  String a = z.next();
                  int b = z.nextInt();
                  if(a == null ? user == null : a.equals(user))
                  checkname = true;
                  }
                  if(checkname)
                  System.out.println("Username is already exists and used, please type another one");
                  else
                  {
                  Formatter x = null;
                  try{
                  FileWriter f = new FileWriter("C:\\Users\\فاطمة\\Downloads\\accounts.txt", true);
                  x = new Formatter(f);
                  x.format("%s %s%n",user.toUpperCase(),pass);
                  System.out.println("You registered succesfully");
                  x.close();
                  }
                  catch(Exception e)
                  {
                  e.printStackTrace();
                  }
                  }
                  }                    
                  catch(Exception e){}
                  }
                  else
                      System.out.println("Password and confirm password are not matching");
                  }
  </code></pre>