This question already has an answer here:
I am not sure how you are supposed to read in from system input from a Java file.
I want to be able to call java myProg < file
Where file is what I want to be read in as a string and given to myProg in the main method.
Any suggestions?
Well, you may read
System.in
itself as it is a validInputStream
. Or also you can wrap it in aBufferedReader
:You would read from
System.in
just like you would for keyboard input using, for example, InputStreamReader or Scanner.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.You can call
java myProg arg1 arg2 ...
:You probably looking for something like this.