一.最原始的方法—使用InputStreamReader和BufferedReader两个类
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s=br.readLine();
System.out.println("I found the text \"" + matcher.group() + "\" starting at index " + matcher.start() + " and ending at index " + matcher.end() + ".");
(JAVA中\是转义字符)
二.先进一点的方法—使用Scanner类
Scanner sca=new Scanner(System.in);
String s=sca.nextLine();
System.out.printf( "I found the text \"%s\" starting at index %d and ending at index %d.%n", matcher.group(), matcher.start(), matcher.end() );
三最先进的方法—使用Console类
Console col=System.console();
String s=console.readLine();
console.format("I found the text \"%s\" starting at index %d " + "and ending at index %d.%n", "something",10,100);