Just one.
The example program reads just one line of text, no matter how many lines are in the file. Of course, the program could be written to read more than one line of data.
Here is an example input file, named input.txt
.
This is line one of the file. This is line two of the file. The last line of the file.
Here is what the above program does when input.txt
is redirected to it as input:
C:\temp>java Echo < input.txt Enter your input: You typed: This is line one of the file. C:\temp>
Using PowerShell do this
C:\temp> type input.txt | java Echo Enter your input: You typed: This is line one of the file. C:\temp>
What will scan.nextLine()
return if a line of the text file contains only the newline character?
This would happen if the user just hit "enter" in response to the prompt.
line = scan.nextLine();