Java 获取键盘输入
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test{
public static void main(String args[]){
System.out.print("请输入内容:");
/*
* 获取键盘输入方法一
Scanner input = new Scanner(System.in);
String s = input.nextLine();
System.out.println("输入内容为:"+s);
*/
// 获取键盘输入方法二
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print("Input: ");
String line;
try {
line = br.readLine();
System.out.print("Show: " + line);
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
}
欢迎访问:wenhao.ink