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 {

}
}
}
posted @ 2012-01-18 17:02  hnrainll  阅读(5505)  评论(0编辑  收藏  举报