I am trying to read a series of integers from a file into an ArrayList but when accessing numbers.get(0), I get the Out of Bounds Exception, presumably because nothing has been written to the list.
ArrayList<Integer> numbers = new ArrayList<Integer>();
public void Numbers() throws IOException{
File file = new File("Numbers.txt");
Scanner inputFile = new Scanner(file);
while (inputFile.hasNext()){
numbers.add(inputFile.nextInt());
}
inputFile.close();
}
Any help would be greatly appreciated. I can provide more code snippets if needed.
numbers.get(0). Where is this code?