可能重复:
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);
}
}
}
始终没有控制台。 为什么呢? 怎么修? 谢谢。
You don't have any console associated.
As per javadoc
Returns the unique Console object associated with the current Java
virtual machine, if any, otherwise null
EDIT:
From Console 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.