Using a File Scanner#
Download starter code
These questions are to assess your understanding of how to use Scanner
s and File
s to read through and process a file.
The program on the right attempts to read the file "newFile.txt"
in token by token and print it to the console on a single line of output. We’ve conveniently forgotten to adapt the method header of main
to acknowledge we are handling files, and we’ve left the choice of Scanner
method used to read in each token as an exercise for you. Remember that on each iteration of the while
loop, we are checking to see that a single token is present in the Scanner
, that means we should only read in a single token on each iteration. You should print each token followed by a single space so that the tokens are kept separate on the console. You do not need to worry about removing the trailing space from the final token on the line for this exercise.