Java Scanner String input
The nextLine method is included in your print, so when you include it at the start then the first line ("Hello World") is stored in input and it is not touched again. Then, when the nextLine in the println method runs, it checks for the next line's content ("I am a file"), and prints "1 I am a file" because it is the first iteration of the loop. It then works successfully in getting and printing the rest of the lines of input.

The next method gets the next word in this context, so using it would cause "Hello" to be stored in input and, as input is never used again, forgotten. nextLine then gets the rest of the line's content and continues successfully for other input lines.

Neither methods are required to start with because the call to nextLine within println runs successfully for each iteration.