Scanner:
An object that reads text from input sources such as System.in, Files, and many other sources.
Anyways, you can use a scanner to get system inputs, which is exampled here.
Code:
Scanner systemInput = new Scanner(System.in);
String tempS = systemInput.nextLine();
while(!tempS.equalsIgnoreCase("?exit"))
{
System.out.println("Hmm, so you aren't ready to exit yet huh?");
tempS = systemInput.nextLine();
}
Every time Scanner.nextLine() is called, it gets an input from the System Input/Output screen.
Reading from a file:
Scanners can indeed be used to read files. One example of this is exampled below.
Code:
public void read(String filename)
{
Scanner fileInput = new Scanner(new File(filename));
String tempS;
while(fileInput.hasNextLine)
{
tempS = fileInput.nextLine();
System.out.println("Next Line: " + tempS);
}
}
You can also return more than just nextLine()
You can also use the following:
// nextBigDecimal()
// nextBigInteger()
// nextBoolean()
// nextByte()
// nextDouble()
// nextFloat()
// nextInt()
// nextLong()
// nextShort()
// useDelimiter(String pattern) - Sets this scanner's delimiting pattern to a pattern constructed from the specified
A detailed explanation can be found here:
Scanner (Java 2 Platform SE 5.0)