title: Reading data from a file to an object?
body: <p>Ok another question about my program that I'm writing called "Flight." In my tester I am creating an object from the Flight class called myFlight. The object has several fields (flight name, miles traveled, etc) but what I'm doing is reading the data from a file called input.txt and trying to put it into the object that I created. There are five lines of information on the file that I'm reading. For some reason I can't quite get it right, if anyone could help me fix this problem I would greatly appreciate it.</p>
  
  <p>Here is the Constructor that has all the fields from my Flight class:</p>
  
  <pre><code> public Flight(String name, int num, int miles, String origin, String destination)
    {
      Airlinename = name;
      flightnumber = num;
      numofmiles = miles;
      Origincity = origin;
      Destinationcity = destination;
    }
  </code></pre>
  
  <p>And the part of my program where I created the object and try to read the data from the file. I had created a blank constructor in my class too because I wasn't sure if I was supposed to put anything in the object when I created it.</p>
  
  <pre><code>Flight myFlight = new Flight();
  
      File myFile = new File("input.txt");
      Scanner inputFile = new Scanner(myFile);
  
      while (inputFile.hasNext())
      {
        myFlight = inputFile.nextLine();
      }
  
      inputFile.close();
    }
  }
  </code></pre>