19 How to load data dynamically from keyword using java.io.Console in Java?

For Ex: In this I am reading string data and password data and save password into the file "test.text".

ConsoleDemo.java

import java.io.Console;
import java.io.FileWriter;
import java.io.IOException;
class ConsoleDemo{

public static void main( String args[] ) throws IOException{
Console con = System.console();

System.out.println("\n\n Enter the Data: ");
String s1=con.readLine();
    System.out.println("\n\n s1:"+s1);

System.out.println("\n\n Enter Some Secure Data: ");
char[] c=con.readPassword();
System.out.println("\n\n c:"+c);
FileWriter fw = new FileWriter("C:\\Users\\Atharv Agrawal\\Desktop\\test.txt");
fw.write(c);
fw.flush();
}
}

Output:  


test.txt :


Previous
Next Post »