今天在Eclipse中写一个小程序,用到了Console,结果在运行时报空指针,但是在命令行里面运行却正常。
package g2w.playground.console;
import java.io.Console;
public class ConsoleLogin {
private static String USERNAME = "greatghoul";
private static String PASSWORD = "mypass";
public static void main(String[] args) {
Console console = System.console();
String username = console.readLine("username: ");
String password = new String(console.readPassword("password: "));
if (USERNAME.equals(username) && PASSWORD.equals(password)) {
console.printf("Hi, there! Dear %s.", username);
} else {
console.printf("Invalid username or password.");
}
}
}
Java API 中 写道
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.
看来是用不了,得用Scanner才行。
via: http://www.codeguru.com/forum/showthread.php?t=487190
分享到:
相关推荐
card.io for eclipse 根据最新版card.io编译,绝对好用
Eclipse 进行 ANT 时错误 Javadoc failed java.io.IOException Cannot run program javadoc
标签:eclipse、jgit、org、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心...
使用org.eclipse.paho.client.mqttv3实现mqtt 消息队列,发布消息及回调,订阅消息及回调
java中代码折叠插件com.cb.eclipse.folding,com.cb.eclipse.folding_1.0.6.jar,使用方法百度,亲测可用,java中代码折叠插件com.cb.eclipse.folding,com.cb.eclipse.folding_1.0.6.jar,使用方法百度,亲测可用.java中...
Addison.Wesley.Eclipse.Rich.Client.Platform.Designing.Coding.and.Packaging.Java.Application包括书和源码
org.eclipse.equinox.p2.examples.rcp.cloud.rarorg.eclipse.equinox.p2.examples.rcp.cloud.rarorg.eclipse.equinox.p2.examples.rcp.cloud.rar
mqtt java版本的源码,版本号1.2.0,有兴趣的可以下载,mqtt广泛用于物联网,智能家居,大家快来下载吧 引入Android studio步骤: 1.讲jar更改为zip解压 2.创建library moudle,以org.eclipse.paho.client.mqttv3...
标签:eclipse、jgit、org、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请...
标签:eclipse、jetty、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心...
从https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/下载的org.eclipse.paho.client.mqttv3的Java包
eclipse学习资料Wrox.Professional.Eclipse.3.for.Java.Developers.eBook-kB
赠送jar包:org.eclipse.jgit....标签:eclipse、jgit、org、lfs、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持
Eclipse酒店管理系统java.pdf
Eclipse酒店管理系统java.docx
Eclipse酒店管理系统java.doc
20180207凌晨,针对eclipse 4.7 修复了 代码折叠的某个插件的一些无法打开的bug和图标显示问题 本人使用的是eclipse 4.7 oxy版本 具体安装方式放到plugins中去或者用links就不说了 20180207亲测可用,本来就是本人用...
MQTTv5版的客户端库,原地址:https://github.com/eclipse/paho.mqtt.java。 本资源合入了解决低于android7.0报错Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.net.ssl.SNIHostName"的...
From cover to cover, this book is pure Eclipse, covering hundreds of skills ... We start from the most basic Java development and work up to creating your own plug-in editors for the Eclipse environment.
Draw.io可以下载到windows、mac、LInux三个平台的客户端免费直接使用。下载后直接安装,就可以在电脑上直接启动「Draw.io」,没有网络时也可流畅的运行,而制作好的流程图可以存储为XML文件。 目前Draw.io经过多年...