简单点说就是在javaw.exe中无法获取Console Methods to access the character-based console device, if any, associated with the current Java virtual machine.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.If this virtual machine has a console then it is represented by a unique instance of this class which can be obtained by invoking the System.console() method. If no console device is available then an invocation of that method will return null.
java.exe是win32控制台应用,javaw.exe是一个win32的GUI应用,这是它们的根本区别
1、java启动的程序是命令行程序或阻塞程序,如果该程序未执行完毕或未被关闭,则所打开的命令行将被阻塞,不能执行其它命令如dir等,可以通过Ctrl+C等方式关闭程序;
2、javaw启动的程序是窗口程序或非阻塞程序,在使用该命令运行程序后,可接着在命令行中执行下一命令,且启动的程序与命令行无关不依赖命令行,不能通过Ctrl+C关闭。
String str=System.console().readLine();
在java 和 javaw 里面执行时获取控制台的情况
简单点说就是在javaw.exe中无法获取Console Methods to access the character-based console device, if any, associated with the current Java virtual machine.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.If this virtual machine has a console then it is represented by a unique instance of this class which can be obtained by invoking the System.console() method. If no console device is available then an invocation of that method will return null.