我试图通过禁用回显来掩盖密码,但它不起作用....
通过屏蔽我的意思是输出*而不是密码本身....
我查看了readPassword
控制台的功能,但它只是禁用了回显。
我是初学者,所以请详细描述...
import java.io.*;
import java.util.*;
//import java.nio.charset.Charset;
//import sun.nio.cs.StreamDecoder;
//import sun.nio.cs.StreamEncoder;
/*class output1 extends OutputStream
{
public void write(int b)
{
}
}
class input1 extends InputStream
{
}*/
class testi
{
static native boolean echo(boolean on) throws IOException;
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//PrintStream out1;
System.out.println("Enter a line: ");
try {
//cin = new InputStreamReader(System.in);
//out1=new PrintStream(OutputStream out);
int c;
while ((c = br.read()) != -1) {
//out1.write((int)('*'));
echo(false);
System.out.print("*");
}
echo(true);
} finally {
if (br != null) {
br.close();
}
/*if (out1 != null) {
out1.close();
}*/
}
}
}
这将在控制台(cmd)中运行..
提前谢谢... :)
PS我编程太差了