title: Having trouble reading and printing out a .csv file
body: <pre><code>package animalfilereader;
  
  import java.io.BufferedReader;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Scanner;
  import java.util.*;
  
  public class AnimalFileReader {
  
      public static void main(String[] args) throws IOException {
  
          // Creates new Object of BufferedReader for the file animals.csv
  
       BufferedReader reader = new BufferedReader(new FileReader(
                  "\\Users\\Greg\\Desktop\\hobbies and personal\\School\\Classwork\\Java 2\\Week 3\\Individual\\AnimalFileReader\\src\\animalfilereader\\animals.csv"));
  
          // reads file in sections
  
         String line = null;
          Scanner scanner = null;
          int index = 0;
          List&lt;Animal&gt; aniList = new ArrayList&lt;&gt;();
      // While lines are not null this runs if compiler detects no data program ends outputs results
          while ((line = reader.readLine()) != null) {
              Animal ani = new Animal();
              scanner = new Scanner(line);
          // searches for Delimiter comma to separate forms of data
              scanner.useDelimiter(",");
              //assigns values to different indexes
          while (scanner.hasNext()) {
                  String data = scanner.next();
                  if (index == 0)
                      ani.setId(Integer.parseInt(data));
                  else if (index == 1)
                      ani.setName(data);
                  else if (index == 2)
                      ani.setType(data);
                  else if (index == 3)
                      ani.setAge(data);
                  else
                      System.out.println("invalid data " + data);
                  index++;
              }
              index = 0;
              aniList.add(ani);
          }
          //Iterator use
  
       System.out.print("Animal file: ");
        Iterator itr = aniList.iterator();
        while(itr.hasNext()) {
           Object element = itr.next();
           System.out.print(element + " ");
        }
        System.out.println();
  
          //close reader
          reader.close();
          //non iterator
          System.out.println(aniList);
  
      }
  
  }
  </code></pre>
  
  <p>Followed by the classes and .csv file</p>
  
  <pre><code>package animalfilereader;
  /**
   * @author Greg
   */
  public class Animal {
  
      private int id;
      private String name;
      private String type;
      private String age;
  
      //getters and setters
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public String getType() {
          return type;
      }
      public void setType(String type) {
          this.type = type;
      }
      public String getAge() {
          return age;
      }
      public void setAge(String age) {
          this.age = age;
      }
      // appending and reading 
      @Override
      public String toString(){
          return "\nID = "+getId()+" Name: "+getName()+" Type = "+getType()+" Age = "+getAge();
      }
  }
  </code></pre>
  
  <p>animals.csv</p>
  
  <pre>
  1,Timone,Meerkat,5 years old 
  2,Pumba,Warthog,7 years old 
  3,Simba,Lion,3 years old 
  4,Rafiki,Monkey,50 years old
  </pre>
  
  <p>I keep getting this error</p>
  
  <pre>
  Exception in thread "main" java.lang.NumberFormatException: For input string: "data"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      at java.lang.Integer.parseInt(Integer.java:580)
      at java.lang.Integer.parseInt(Integer.java:615)
      at animalfilereader.AnimalFileReader.main(AnimalFileReader.java:51)
  Java Result: 1
  BUILD SUCCESSFUL (total time: 1 second)
  </pre>
  
  <p>Not sure what is going on. Can someone point me in the right direction?</p>