Learning objectives
Explain that a file keeps its data after a program stops running, and open a text file for reading by passing a File object, built from the file name, to a Scanner constructor
State what file-reading code requires: import statements for File, IOException and Scanner, and throws IOException in the header of any method that opens the file, so that an invalid file name ends the program
Use the Scanner methods next, nextLine, nextInt, nextDouble and nextBoolean to read values, and predict the InputMismatchException raised when the next value is of the wrong type
Write a while loop controlled by hasNext that reads a file to its end, and close the Scanner once reading is finished
Use split with a delimiter to break a line of text, such as a comma-separated record, into a String array, and convert the parts with Integer.parseInt and Double.parseDouble
Store the values read from a file in an array or an ArrayList, and explain the extra step needed when nextLine is called after nextInt or nextDouble on the same input
Continue with a revision plan
These learning objectives are available to everyone. Sign in with an eligible plan to read the full note and worked examples.
