사용자 비밀번호를 읽으려면 System.console()
을 사용하고 있습니다.Java : 파일에서 비밀번호를 읽는 방법?
내 코드 : 나는 간단 (Redhat
에서) 실행하고 때
Console console = System.console();
if (console == null) {
throw new RuntimeException("No console is available for input");
}
System.out.print("Enter the password: ");
String password = new String(console.readPassword());
그것은 잘 작동합니다.
java -jar my_jar.jar < password.txt
내가 얻을 :
없음 콘솔 입력을 사용할 수 없습니다 내가 텍스트 파일에서 암호를 읽을 때
문제
입니다.
어떻게 해결할 수 있습니까?
이것은 알려진 버그/문제와 유사합니다. System.console은 null을 반환합니다. 정보 및 가능한 해결 방법은이 질문에 대한 답변을 참조하십시오 : http://stackoverflow.com/questions/4203646/system-console-returns-null – Akunosh