1

The file contains two strings on different lines then two ints on the same line which are all used in the constructor for an array based on a class in my program called Flight.

    Scanner fileIn = null;

    try 
    {
        fileIn = new Scanner(new File("flights.txt"));
        
    }catch(FileNotFoundException e) {
        
        throw new IllegalArgumentException("File was not found");
        
    }
    
    int count = 0;
    while(fileIn.hasNextLine()) 
    {
        
        fileIn.nextLine();
        count += 1;
        
    }
    
    flights = new Flight[count/3];
    
    count = 0; 
    

    while(fileIn.hasNextLine()) 
    {
        String name = fileIn.nextLine();
        String des = fileIn.nextLine();
        int h = fileIn.nextInt(); //the two ints that im taking in are on the same line seperated by a space 
        int m = fileIn.nextInt();
        Time t = new Time(h, m);
        flights[count] = new Flight(name,des,t); //I need the data to be saved into this array based on the Flight class 
        count++;
    }
  • This is an example of the input that the program would read: DA163 New York 15 45 – Haarith Jayakumar Jan 20 '22 at 23:42
  • 1
    Two issues that I can see: [Java Scanner "rewind"](https://stackoverflow.com/q/16573790) and [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/q/13102045) – 001 Jan 20 '22 at 23:46
  • Put your sample input in your question, not a comment. – tgdavies Jan 20 '22 at 23:48

0 Answers0