How To Accept Password From Console in Java如何接受密碼,從控制台在Java
Finally you can easily accept password from console in Java, without echoing them.最後,您可以很容易地接受密碼,從控制台在Java中,沒有附和他們。
This long unmet need has been addressed in這一長期未得到滿足的需求已得到解決在 JDK 1.6的JDK 1.6 codeline. codeline 。
A new class -新一類- java.io.Console java.io.console has been defined to handle console I/O.已確定了處理控制台的I / O 。
To accept password from console in接受密碼,從控制台在 JDK 6.0 (aka JDK 1.6)的JDK 6.0 (又名的JDK 1.6 ) use either:使用:
public char[] readPassword() 市民焦[ ] readpassword ( )
or或
public char[] readPassword(String fmt, Object… args) 市民焦[ ] readpassword (字符串裂變材料條約,對象… args )
Sample code: Console cons; char[] passwd; if ((cons = System.console()) != null && (passwd = cons.readPassword(”[%s]“, “Password:”)) != null) { // Use the passwd for authentication etc. ….; // Your code // After you are done zero the character array in memory for reducing security risk java.util.Arrays.fill(passwd, ‘ ‘); }示例代碼:控制台的意見;燒焦[ ]密碼;如果( (考慮= system.console ( ) ) ! =空& & (密碼= cons.readpassword ( “ [ % ] ” , “密碼: ” ) ) ! =空) ( / /使用密碼進行身份驗證等… … 。 ; / /您的代碼/ /後,你是做了零的性質數組在內存中為減少安全風險java.util.arrays.fill (密碼, ' ' ) ; ) So could I entice you yet to所以我想引誘你仍未 download JDK 1.6下載的JDK 1.6 ? ?
Filed under提起下 Headline News頭條新聞 , , How To如何 , , Java Software Java軟件 , , Tech Note技術說明 | |
| |
RSS 2.0 2.0 | |
Email this Article電子郵件此文章
You may also like to read您也可以想讀 |





January 12th, 2006 at 10:45 am 2006年1月12日上午10時45分
[...] India Fourth Largest Internet User How To Accept Password From Console in Java » JDK1.6 / JDK 6.0 Downloaded? [ … … ]印度第四大互聯網用戶如何接受密碼,從控制台在Java » jdk1.6 /的JDK 6.0下載? January 12th, 2006 by AngsumanChakraborty [...] 2006年1月12日由angsumanchakraborty [ … … ]
June 8th, 2006 at 6:21 am 2006年6月8日在上午06時21分
thanks for the service you provided to me.感謝您的服務提供給我。
November 19th, 2007 at 7:46 pm 2007年11月19日在下午7點46分
Console c = System.console();控制台c = system.console ( ) ;
if(c != null){如果(三! =空) (
String user = new String(c.readLine(”Enter user:”));字符串用戶=新字串( c.readline ( “輸入用戶:"));
String pwd = new String(c.readPassword(”Enter pwd:”));字符串密碼=新字串( c.readpassword ( “輸入密碼:"));
c.printf(”%20s”,user); c.printf ( “ % 20 ” ,用戶) ;
c.printf(”\n%20s\n”,pwd); c.printf ( “ \頻數百分比20多歲的\ n ” ,密碼) ;
}else )否則
System.out.println(”Console is unavailable”); system.out.println ( “控制台是不可用” ) ;
注意運行環境為:jdk1.6+jcreator3.5.注意運行環境為: jdk1.6 + jcreator3.5 。
如果jcreator4.0的話,得到的c總是null.如果jcreator4.0的話,得到的c總是空。
March 28th, 2008 at 6:46 am 2008年3月28日在上午06時46分
it,s very nice它,硫很好