title: Writing into text file from ArrayList that has multiple values per ArrayList object (java)
body: <p>I am trying to save my ArrayList into a text file. But the format of how it is saved is wrong. My code:</p>
  
  <pre><code>ArrayList&lt;Vehicle&gt; vehs = new ArrayList&lt;Vehicle&gt;();
  
  vehs.add(new Vehicle("QJT123", "Starlet 99", 35.0, 190000));
  vehs.add(new PremiumVehicle("TUX132", "BWM 05  ", 90.0, 12000, 100, 10000, 5000));
  </code></pre>
  
  <p>Constructor used for these 2:</p>
  
  <pre><code>public PremiumVehicle(String vehicleID, String description, double dailyRate, int odometer, int allowance, int serLength, int lastOdo) //subclass
  
  public Vehicle(String vehicleID, String description, double dailyRate, int odometer) //Superclass
  </code></pre>
  
  <p>Both of these are stored into the Vehicle ArrayList. Code to save to text file:</p>
  
  <pre><code>private static void saveFile(ArrayList&lt;Vehicle&gt; vehs){
      File fileName = new File("VehicleList.txt");        
  
      try {
          FileWriter fw = new FileWriter(fileName);
          Writer output = new BufferedWriter(fw);
  
          for (int i = 0; i &lt; vehs.size(); i++){
              output.write(vehs.get(i).toString() + "\n");
          }
  
          output.close();
  
      } catch (Exception e) {
          JOptionPane.showMessageDialog(null, "I cannot create that file");
      }
  }
  </code></pre>
  
  <p>My output in VehicleList.txt:</p>
  
  <pre><code>vehicle ID = QJT123 Description = Starlet 99    Status = A  Daily Rate = 35.0 Odometer reading = 190000vehicle ID = TUX132  Description = BWM 05    Status = A  Daily Rate = 90.0   Odometer reading = 12000 Mileage allowance = 100    service length = 10000  Last Service = 5000
  </code></pre>
  
  <p>How do i make it such that each new line is added when writing in a new ArrayList object, e.g:</p>
  
  <pre><code>vehicle ID = QJT123 Description = Starlet 99    Status = A  Daily Rate = 35.0 Odometer reading = 190000
  vehicle ID = TUX132 Description = BWM 05    Status = A  Daily Rate = 90.0   Odometer reading = 12000 Mileage allowance = 100    service length = 10000  Last Service = 5000
  </code></pre>
  
  <p>I've tried using <code>vehs.get(i).toString() + "\n"</code> but it doesn't seem to work.</p>