system.in

Reading in from System.in - Java [duplicate]

大兔子大兔子 提交于 2019-11-26 02:36:01
问题 This question already has an answer here: How to use java.util.Scanner to correctly read user input from System.in and act on it? 1 answer 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? 回答1: You can use System.in to read from the standard input. It works just like entering it from a keyboard. The OS handles

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

痴心易碎 提交于 2019-11-25 21:35:41
问题 This is meant to be a canonical question/answer that can be used as a duplicate target. These requirements are based on the most common questions posted every day and may be added to as needed. They all require the same basic code structure to get to each of the scenarios and they are generally dependent on one another. Scanner seems like a \"simple\" class to use, and that is where the first mistake is made. It is not simple, it has all kinds of non-obvious side effect and aberrant behaviors