Reading in from System.in – Java [duplicate]

You can use System.in to read from the standard input. It works just like entering it from a keyboard. The OS handles going from file to standard input. import java.util.Scanner; class MyProg { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(“Printing the file passed in:”); while(sc.hasNextLine()) System.out.println(sc.nextLine()); } }

How to use java.util.Scanner to correctly read user input from System.in and act on it?

Idiomatic Example: The following is how to properly use the java.util.Scanner class to interactively read user input from System.in correctly( sometimes referred to as stdin, especially in C, C++ and other languages as well as in Unix and Linux). It idiomatically demonstrates the most common things that are requested to be done. package com.stackoverflow.scanner; import … Read more