title: How do I write to a new line using FileWriter in Java?
body: <p>I've been trying to make a simple bank account in Java and want to save the inputted users' name into a .txt doc. Only problem is that the name is replaced on the first line of the text doc each time I run the code.</p>
  
  <pre><code>package bank.account;
  import java.util.Scanner;
  import java.io.*;
  
  public class ATM 
  {
      public static void main(String[] args){
  
  
      Scanner sc = new Scanner(System.in);
      BankAccount userAccount = new BankAccount();
      System.out.println("Please enter your name in order to make a new account:");
  
  
      String fileName = "name.txt";
      try {
          FileWriter fileWriter =
                  new FileWriter(fileName);
          BufferedWriter bufferedWriter = 
                  new BufferedWriter(fileWriter);
  
          String name = sc.nextLine();
          userAccount.setaccName(name);
                  bufferedWriter.write(userAccount.getaccName());
                  bufferedWriter.close();
  
      }
      catch(IOException ex) {
              System.out.println(
                  "Error writing to file '"
                  + fileName + "'");
  
          }
  
      System.out.println("Please enter the amount you would like to deposit");
      double money = sc.nextDouble();
      userAccount.deposit(money);
      System.out.println(userAccount.getaccBalance());
      System.out.println(userAccount.getaccName()+ " your balance is " + userAccount.getaccBalance());
  
      }
  
  }
  </code></pre>