我试图编写以下代码,询问用户他们的用户名和密码:
public static void main(String[] argv) {
Console console = System.console();
String USER = console.readLine("Username: ");
char[] PASSWORD = console.readPassword("Enter password");
Arrays.fill(PASSWORD, ' ');
}
但是,我收到以下错误:
nameless@nameless:~/Desktop/File$ Console console = System.console();
bash: syntax error near unexpected token `('
nameless@nameless:~/Desktop/File$ String USER = console.readLine("Username: ");
bash: syntax error near unexpected token `('
nameless@nameless:~/Desktop/File$ char[] PASSWORD = console.readPassword("Enter password");
bash: syntax error near unexpected token `('
nameless@nameless:~/Desktop/File$ Arrays.fill(PASSWORD, ' ');
附注:我试图用它来在Oracle SQL中输入数据库。
答案 0 :(得分:0)
我想您可以使用本机扫描程序而不是控制台
来实现相同的功能尝试这可以是任何帮助。
public static void main( String[] args ) {
public static void main( String[] args ) {
try (Scanner scanner = new Scanner( System.in );) {
System.out.println( "Username: " );
String USER = scanner.nextLine();
System.out.println( "Enter password" );
String PASSWORD = scanner.nextLine();
Arrays.fill( PASSWORD.toCharArray(), ' ' );
} catch ( Exception e ) {
e.printStackTrace();
}
}