为什么Eclipse或IntelliJ中的控制台总是为空? [英] Why Console in Eclipse or IntelliJ always null?

查看:761
本文介绍了为什么Eclipse或IntelliJ中的控制台总是为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

System.Console()返回null

代码:

public class Demo {

public static void main(String[] args){
    Console c = System.console();
    if (c == null) {
        System.err.println("No console.");
        System.exit(1);
    }else {
        System.out.println("Console is.");
        System.exit(0);
    }
}

}

总是没有控制台。为什么怎么修?谢谢。

always No console. Why ? How to fix? Thanks.

推荐答案

您没有任何控制台关联。

You don't have any console associated.

根据 javadoc


返回与当前Java $ b $相关联的唯一控制台对象b虚拟机(如果有的话)否则为空

Returns the unique Console object associated with the current Java virtual machine, if any, otherwise null

编辑:

控制台javadoc

虚拟机是否具有控制台取决于底层平台以及虚拟机的调用方式。如果虚拟机从交互式命令行启动,而不重定向标准输入和输出流,则其控制台将存在,并且通常将连接到启动虚拟机的键盘和显示器。如果虚拟机自动启动,例如通过后台作业调度程序启动,那么它通常没有控制台。

Whether a virtual machine has a console is dependent upon the underlying platform and also upon the manner in which the virtual machine is invoked. If the virtual machine is started from an interactive command line without redirecting the standard input and output streams then its console will exist and will typically be connected to the keyboard and display from which the virtual machine was launched. If the virtual machine is started automatically, for example by a background job scheduler, then it will typically not have a console.

这篇关于为什么Eclipse或IntelliJ中的控制台总是为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆