public class Talker {
   public static void main(String[] args) {
      Console c = System.console();
      String u = c.readLine("%s", "username:");
      System.out.println("hello "+u);
      char[] pw;
      if(c!=null && (pw = c.readPassword("%s", "password:"))!= null){
         System.out.println("exe");
      }
   }
}

解决方案 »

  1.   

    JDK 6中提供了java.io.Console类专用来访问基于字符的控制台设备。如果你的Java程序要与Windows下的cmd或者Linux下的Terminal交互,就可以用这个Java Console类代劳。       Console c = System.console();
          if(c!=null){
          String u = c.readLine("%s", "username:");
          System.out.println("hello "+u);
          char[] pw;
          if(c!=null && (pw = c.readPassword("%s", "password:"))!= null){
             System.out.println("exe");
          }
          }
      

  2.   

    你没有1.6API吗? 用的时候多看看API的解释!
      

  3.   

    java.io.Console 只能用在标准输入、输出流未被重定向的原始控制台中使用,在 Eclipse 或者其他 IDE 的控制台是用不了的。
      

  4.   

    Console是控制台,是输出结果的地方,但不是唯一的结果输出地;