0
所以,當過我嘗試編譯這段代碼,我得到:屏蔽從控制檯輸入密碼,「無法解析符號‘控制檯’」
的java:找不到符號 符號:類控制檯 位置:級Java .lang.System
我不明白爲什麼當我啓動控制檯對象,System.console()不能得到解決......
import java.io.Console;
import java.util.Arrays;
import java.util.Scanner;
public class User {
Scanner input = new Scanner(System.in);
Console console = new System.console();
private String userID, userPW, userPIN;
private char[] password = new char[6];
public String getUserID() {
return userID;
}
public void setUserID(String userID) {
this.userID = userID;
}
public String getUserPW() {
return userPW;
}
public void setUserPW(String userPW) {
this.userPW = userPW;
}
public String getUserPIN() {
return userPIN;
}
public void setUserPIN(String userPIN) {
this.userPIN = userPIN;
}
public void setUserInfo() {
System.out.print("Please enter your User ID : ");
this.setUserID(input.nextLine());
System.out.print("Please enter your Password: ");
this.setUserPW(input.nextLine());
this.password = console.readPassword("Enter password");
Arrays.fill(this.password, '*');
}
哇......我盯着這個好一個小時。非常感謝! – MK3GTX 2013-05-12 07:13:37