I am trying to read a file into an array using the code shown below. My issue is that I believe when referencing the elements in my array, I'm referencing empty elements so I'm unsure as to why my file is not being properly copied into the array. The file and code is all in the same file.
int column = 0;
int arraySize = 0;
String fileName = "SuperBowlWinners.txt";
File file = new File(fileName);
Scanner inputFile = new Scanner(file);
while (inputFile.hasNext()) {
inputFile.nextLine();
arraySize++;
}
String[][] superBowl = new String[arraySize][1];
while (inputFile.hasNext()) {
for (int index = 0; index < superBowl.length; index++) {
superBowl[index][0] = inputFiles.next();
superBowl[index][1] = inputFiles.nextLine();
}
}
The first while loop is used to determine the array size and I need to two columns, so that's why 1 is in the second []. Is the instance not being created between with the file? How do I allow the data to be read into the array from the file?