gpt4 book ai didi

java - 为什么Java的IDE中没有控制台?

转载 作者:行者123 更新时间:2023-11-30 07:15:24 27 4
gpt4 key购买 nike

为了获得对 Java 中控制台的引用,需要编写

Console console = System.console();

但是,当尝试在 IDE 中执行此操作时,控制台将被初始化为 null。为什么IDE中没有控制台?允许控制台存在同时直接从终端运行程序而不是在 IDE 中运行程序的思考过程是什么?

最佳答案

引用自javadocs :

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.

您的 IDE 以非交互方式运行 jvm(没有键盘连接到输入),因此控制台在那里不可用。

关于java - 为什么Java的IDE中没有控制台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38498515/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com