Disagree. If you want to use a Scanner, you can ensure it will only pass the required input. If you are going to read whole lines, why bother with Scanner? Use a buffered reader reading from System.in.
Matt Wong wrote:. . . if you somewhere want to read input from console it is all delievered as one line - so its best to only use nextline() and parse the input yourself
Input Streams for text files? If you are going to use something other than Scanner for a text file, again use a buffered reader.
. . . file-input with a defined format- all thought datainputstream maybe preferred in such cases . . .
Matt Wong wrote:if you somewhere want to read input from console it is all delievered as one line - so its best to only use nextline() and parse the input yourself
Campbell Ritchie wrote:If you are going to read whole lines, why bother with Scanner? Use a buffered reader reading from System.in.
I have a similar class which usually doesn't use nextLine().
Knute Snortum wrote:. . . I wrote a whole console inputting class call Inputer with only Scanner#nextLine().
That is why we have this sort of forum. We all learn things from the discussions here. I have learnt lots and lots from being disagreed with here, which I am very grateful for.
. . . I hadn't thought of that . . .
which can also be misunderstood. It doesn't mean that Scanner is simple, as I once thought; it means it scans simple text. That means ordinary text; it is not intended for HTML tags or XML tags.
A simple text scanner . . .
Sorry I didn&apost;t have the time to reply last night, but I think we agree on that point; once you have created a utility class to deal with the vagaries of Scanner, which as MW points out are badly documented in many places, you find keyboard input so much easier and more reliable. I think my KeyboardInputs class differs rather from your Inputter class, but I think we both find such classes much easier to use from the keyboard than a plain simple Scanner. The reason is that it is possible to ensure consistent format of the contents of a text file, so nextInt() actually finds an int, but you can't be sure there won't be errors when entering data live from the keyboard.
Knute Snortum wrote:Scanner is great for scanning text files, but I don't like it for getting input from the keyboard. . . . .
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
the value of filler advertising in 2021https://coderanch.com/t/730886/filler-advertising