作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/

import java.io.Console; public class ConsoleLogin { public static void main(String arg[]) { Console con; con = System.console(); if(con == null) { System.out.println("No console available."); return; } String name = con.readLine("name: "); char pw[] = con.readPassword("password: "); String password = new String(pw); System.out.println("The login name is " + name + " and the pass word is " + password); } } ====================== import java.io.Console; public class ConsoleOutput { public static void main(String arg[]) { Console con; con = System.console(); if(con == null) { System.out.println("No console available."); return; } int value = 31520; con.printf("The number %d as hexidecimal is %4X/n",value,value); } } 注意Console这个类的read和write方法是synchronized,而且console可能不存在(当然,你要是使用cmd或者shell则一定存在),最好使用flush刷新display

 

作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/

相关文章:

  • 2021-07-06
  • 2021-07-29
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2022-01-02
猜你喜欢
  • 2022-12-23
  • 2022-01-19
  • 2021-10-03
  • 2022-12-23
  • 2021-10-10
  • 2021-10-22
  • 2021-12-15
相关资源
相似解决方案