import java.io.Console;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReguxTestingHarness {
public static void main(String[] args){
Console console = System.console();
if (console == null)
{
System.err.println("No console.");
System.exit(1);
}
while(true){
Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex:"));
Matcher matcher = pattern.matcher(console.readLine("Enter input string to search:"));
boolean found = false;
while(matcher.find()){
console.format("I found the text \"%s\" starting at" + "index %d and ending at index %d.%n", matcher.group(),matcher.start(),matcher.end());
found = true;
}
if(!found){
console.format("No match found.%n");
}
}
}
}
执行上面的代码,发现在Eclipse里面报No console,在cmd里面执行就ok
JDK是1.6的,是因为Eclipse本来自己就有console了,所以不work嘛?只能用readerbuffer来读?
谢谢啦
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReguxTestingHarness {
public static void main(String[] args){
Console console = System.console();
if (console == null)
{
System.err.println("No console.");
System.exit(1);
}
while(true){
Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex:"));
Matcher matcher = pattern.matcher(console.readLine("Enter input string to search:"));
boolean found = false;
while(matcher.find()){
console.format("I found the text \"%s\" starting at" + "index %d and ending at index %d.%n", matcher.group(),matcher.start(),matcher.end());
found = true;
}
if(!found){
console.format("No match found.%n");
}
}
}
}
执行上面的代码,发现在Eclipse里面报No console,在cmd里面执行就ok
JDK是1.6的,是因为Eclipse本来自己就有console了,所以不work嘛?只能用readerbuffer来读?
谢谢啦
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货