title: Importing from text file into Java Array
body: <p>Currently I am trying to import data from a text file regarding pets and doctors, and sending it to my "petArray" and "doctorArray".</p>
  
  <p>I am extremely new to Java and as such am having great difficulty. This is what ive attempted to do, but it doesnt seem too work.</p>
  
  <p>Please see attached Java code and text file (screenshot at link).</p>
  
  <pre><code> public void readFile() {
      String fileName = "VetManagement.txt";
      Scanner inputStream = null;
      try {
          inputStream = new Scanner(new File(fileName));
      } catch (FileNotFoundException e) {
          System.out.println("Error opening file: " + fileName);
          System.exit(0);
      }
      while (inputStream.hasNextLine()) {
          String line = inputStream.nextLine();
          String initName = "";
          String initSize = "";
          String initType = "";
          String initDoctor = "";
          double initWeight = 0.0;
          int initAge = 0;
  
          if (line.equals("Pets")) {
              inputStream.nextLine();
  
              if (line.equals("type cat")) {
                  initType = "cat";
                  System.out.print(initType);
  
              } else if (line.equals("type dog")) {
                  initType = "dog";
                  System.out.print(initType);
              }
  
              inputStream.nextLine();
  
              if (line.equals("size small")) {
                  initSize = "small";
  
              } else if (line.equals("size medium")) {
                  initSize = "medium";
  
              } else if (line.equals("size large")) {
                  initSize = "large";
  
              } else System.out.println("error");
  
              inputStream.nextLine();
  
              if (line.startsWith("name")) {
                  initName = inputStream.next();
  
              } else {
                  System.out.println("error");
              }
  
              inputStream.nextLine();
  
              if (line.startsWith("weight")) {
                  initWeight = inputStream.nextDouble();
              } else {
                  System.out.println("error");
              }
              inputStream.nextLine();
  
              if (line.startsWith("age")) {
                  initAge = inputStream.nextInt();
              } else {
                  System.out.println("error");
              }
              inputStream.nextLine();
  
              if (line.startsWith("doctor")) {
                  initDoctor = inputStream.toString();
              } else {
                  System.out.println("error");
              }
  
              petArray[sumPets] = new Pet();
              petArray[sumPets].setType(initType);
              petArray[sumPets].setSize(initSize);
              petArray[sumPets].setName(initName);
              petArray[sumPets].setWeight(initWeight);
              petArray[sumPets].setAge(initAge);
              petArray[sumPets].setDoctorName(initDoctor);
  
          } else if (line.equals("Doctors")) ;
  
      }
  
      inputStream.close();
  }
  </code></pre>
  
  <p>TEXT FILE:</p>
  
  <pre>
  Pets
  type cat
  size small
  name Lara
  weight 4
  age 5
  doctor Joao
  type dog
  size large
  name Biro
  weight 15
  age 12
  doctor Maria
  type cat
  size large
  name Benny
  weight 7
  age 10
  doctor no doctor assigned
  Doctors
  name Joao
  specialisation cat
  name Maria
  specialisation dog
  </pre>