I want to read password from console in one my java program. I used
Console newConsole = System.console();
But I could able to declare and initialize console object in my class. I am getting an error message
" the method console() is undefined for the type System" and " Console cannot be resolved or is not a type"
Hence I thought I don't have latest java version and checked my java version using
C:\>java -version
java version "1.7.0_21"
I came to know that I have java 1.7.0_21 which is the latest version but still I am getting error. Anybody could you please help me regarding this.
If I can't use System.console then are there any other method I can use to read password as hidden character from console.
The complete code :
import java.io.console;
public class Test {
public static void main(String[] args) {
Console newConsole = System.console();
}
}
I am getting compiler error in import java.io.console (java.io.console cannot be resolved) and Console newConsole = System.console(); (the method console() is undefined for the type System and Console cannot be resolved or is not a type) line.