1

So I'm working on a school project in which we have to import a list of items from a text file. Here is an example of the file format:

enter image description here

I keep getting an input mismatch exception with this section of code (I have gone from a for loop to a while loop). The 3 things I have to import are name, grade, and rank this is what I have so far:

File myFile = new File("input.txt");
if (!myFile.exists()) {
    System.out.println("Can't Find File");
    System.exit(0);
}

Scanner reader = new Scanner(myFile);
int i = 0;

while (reader.hasNext()) {
    names[i] = reader.nextLine();
    grade[i] = reader.nextInt();
    rank[i] = reader.nextInt();
    i++;
}
reader.close();

How do I go about getting the information to their correct arrays? P.S I can't use ArrayLists (even though I wish I could)

Joel
  • 4,732
  • 9
  • 39
  • 54

0 Answers0