How to read input from command line in Java using Scanner

Java 5 introduced a nice utility called java.util.Scanner which is capable of reading input form command line in Java. Using Scanner is a nice and clean way of retrieving user input from console or command line. The scanner can accept InputStream, Reader or simply path of the file from where to read input. In order to read from the command line, we can pass System.in into Scanner's constructor as a source of input. The scanner offers several benefit over classical BufferedReader approach, here are some of the benefits of using java.util.Scanner for reading input from command line in Java:
Read more »