I'm trying to take the contents of a file into an array. The file contents are positive and negative integers.
This is what I did to find how big I should make the array. inFile is my scanner. I am able to print the contents of inFile, but they won't go into the array. I just get null values.
int arrayLength = 0;
while (inFile.hasNextInt()){
inFile.nextInt();
arrayLength++;
}
This is what I tried to do to get the file contents into the array.
int[] nums = new int[arrayLength]; //make array according to arrayLength
inFile.reset();
//fill array with values from file
for (int n = 0; n > arrayLength; n++) {
nums[n] = inFile.nextInt();
}
Thanks for your help.