title: Check if a .txt file exists. FileWriter.exists method not working
body: <p>SOLVED!!! Thanks for the hand guys got it working. Appreciate it!</p>
  
  <p>I'm writing a program that has user name and password input. I am trying to check if a file exists for a user if the user puts in a user name that already exists when they create a user name and password.</p>
  
  <p>The .exists method isn't working and I cant figure it out. Error cannot find symbol comes back. I've changed things, moved things around and got it down to one error. Tried using loops as well as if statements but using if gets me to only one error .Any help would be great.</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.*;
  
  class UserData 
  {
    public static void main ( String[] args ) throws IOException
    {
    Scanner kb = new Scanner(System.in);
  
    System.out.println("Do you have an account? Yes or No: ");
    String answer = kb.next().trim();
  
    if ((answer.startsWith("N")) || (answer.startsWith("n")))
    {
  
  System.out.println("Create user name: ");
  String user = kb.next().trim();
  
  String fileName = user + ".txt";
  FileWriter userData = new FileWriter(fileName);
  
   if (userData.exists())
   {
     System.out.println("User already exists");
     System.out.println("Create user name: ");
     user = kb.next().trim();
  
     fileName = user + ".txt";
     userData = new FileWriter(fileName);
   }
  
  System.out.println("Create Password: ");
  String ps = kb.next().trim();
  
  userData.write(user + " ");
  userData.write(ps);
  userData.close();
  
  
    }
  
    else if ((answer.startsWith("Y")) || (answer.startsWith("y")))
    {
  System.out.println("Enter user name: ");
  String user = kb.next().trim();
  
  System.out.println("Enter Password: ");
  String ps = kb.next().trim();
  
  String fileName = user + ".txt";
  Scanner inFile = new Scanner(new File(fileName));
  
  String userName = inFile.next();
  String password = inFile.next();
  
  //     If ((userName != user) || (password != ps))
  //     {
  //       System.out.println("User Not Found");
  //       System.out.println("Enter user name: ");
  //       String user = kb.next().trim();
  // 
  //       System.out.println("Enter Password: ");
  //       String ps = kb.next().trim();
  //  
  //       String fileName = user + ".txt";
  //       Scanner inFile = new Scanner(new File(fileName));
  //  
  //       String userName = inFile.next();
  //       String password = inFile.next();
  //     }
  //     else
  //     {
     System.out.println("User Found");
  //     }
  }
  
  
  
  
  
  }}
  </code></pre>