为什么输出是';无控制台';是否要使用java编写以下代码?

为什么输出是';无控制台';是否要使用java编写以下代码?,java,netbeans,Java,Netbeans,以下代码是我从doc.oracle站点复制的完美代码。它在netbeans中编译时没有任何错误,但输出为: 没有控制台。 Java结果:1 我应该怎么做才能让控制台正常工作。是否需要在netbeans设置中进行任何调整?。尽管我在IDE netbeans中有一些java编程经验,但我还是感到困惑。我正在使用最新版本的JDK和Netbean 公共类RegexTestHarness{ /** * @param args the command line arguments */ public s

以下代码是我从doc.oracle站点复制的完美代码。它在netbeans中编译时没有任何错误,但输出为:

没有控制台。 Java结果:1

我应该怎么做才能让控制台正常工作。是否需要在netbeans设置中进行任何调整?。尽管我在IDE netbeans中有一些java编程经验,但我还是感到困惑。我正在使用最新版本的JDK和Netbean

公共类RegexTestHarness{

/**
 * @param args the command line arguments
 */
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");
        }
    }
}
}

我正在使用最新版本的JDK和Netbeans

NetBeans使用自己的控制台,因此根本没有系统控制台。试着在终端上运行它,它应该可以工作

我正在使用最新版本的JDK和Netbeans

NetBeans使用自己的控制台,因此根本没有系统控制台。尝试在终端上运行它,它应该可以工作。

来自:

如果此虚拟机具有控制台,则它由此类的唯一实例表示,该实例可通过调用
System.console()
方法获得。如果没有可用的控制台设备,则调用该方法将返回
null

NetBeans没有
System.console()

使用
System.in
读取
System.out
进行写入。

来自:

如果此虚拟机具有控制台,则它由此类的唯一实例表示,该实例可通过调用
System.console()
方法获得。如果没有可用的控制台设备,则调用该方法将返回
null

NetBeans没有
System.console()

使用
System.in
读取
System.out
进行写入。

供后代使用

public class RegexTestHarness {

public static void main(String[] args) throws IOException{


    while (true) {

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("\nEnter your regex:");

        Pattern pattern = 
        Pattern.compile(br.readLine());

        System.out.println("\nEnter input string to search:");
        Matcher matcher = 
        pattern.matcher(br.readLine());

        boolean found = false;
        while (matcher.find()) {
            System.out.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){
            System.out.println("No match found.");
        }
    }
}
}
为子孙后代

public class RegexTestHarness {

public static void main(String[] args) throws IOException{


    while (true) {

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("\nEnter your regex:");

        Pattern pattern = 
        Pattern.compile(br.readLine());

        System.out.println("\nEnter input string to search:");
        Matcher matcher = 
        pattern.matcher(br.readLine());

        boolean found = false;
        while (matcher.find()) {
            System.out.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){
            System.out.println("No match found.");
        }
    }
}
}

您可能需要打开控制台视图。非常感谢!。我已经找到了问题的真正原因,混乱已经过去。(我来晚了,因为一次路边事故使我远离电脑。)您可能需要打开控制台视图。非常感谢!。我已经找到了问题的真正原因,混乱已经过去。(在这里我太晚了,因为一次路边事故让我远离了电脑。)非常感谢您对控制台有一个非常清晰的想法。我遵循了这个概念。很长一段时间以来,我都是吃力不讨好的人,但是由于一次路边事故,我的视力出现了严重的问题,所以我无法使用电脑。非常感谢您对控制台有了非常清晰的认识。我遵循了这个概念。很长一段时间以来,我一直在吃力不讨好,但由于一次路边事故,我的视力出现了严重问题,因此无法使用计算机。感谢您让我对System.out的NetBeans有了一点了解。现在,我将不再在不存在的地方进行控制台操作。感谢您让我更清楚地了解System.out的NetBeans。现在,我不会在那里安慰那些不存在的人。