Campbell Ritchie wrote:If you get any situation where you don't have a next int, that means the file has a line with 5 or 7 numbers in, or a non‑number, so the file is corrupt and you should stop reading.
I don't agree. The formatting of the file itself is inconsequential. It's just a bunch of integers that get distributed over different lists.
If you want to deduce the number of columns from the formatting,
you should probably perform some special processing on the first line first.
If you don't care that the number of integers is a multiple of the number of columns, but you still want to check that the input doesn't contain invalid tokens, you should probably do it like this:
Should I throw a different sort of exception?
InputMismatchException or an appropriate custom exception.