用户在控制台输入的内容打印在控制台上:
如下例子:用户在控制台中输入内容,回车后,会将内容再次打印到控制台上,下面的readLine()方法是一个阻塞式方法,会一直等待用户的输入,当用户输入 over 后,打印输入内容后程序结束。
public static void main(String[] args) {
BufferedReader br = null ;
try {
br = new BufferedReader(new InputStreamReader(System.in));
String len;
while ((len = br.readLine()) != null) {
System.out.println(len);
if(len.equals("over")){
break ;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}