Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.Console console=System.console() returns null in windows

807580Sep 4 2009 — edited Sep 4 2009
Hi,

I am trying to capture userid/password on console and using java 6 console api for that.

But it returns null, when I call System.console().

Can anyone please let me know the possible reason Or how can I use console API to capture password on console. The code, what I am using is

public static String getUserInfoFromCommandLine(String caption, boolean isPassword){
String str=null;
Console cons = System.console();
if(cons!=null){
if(isPassword==false){
str = cons.readLine("[%s]", caption);
}else{
char[] passwd = cons.readPassword("[%s]", caption);
str=String.valueOf(passwd);
}
}else{
System.out.println("System Does Not Support Console Operation.");
System.exit(0);
}
return str;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 2 2009
Added on Sep 4 2009
4 comments
1,452 views