import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
private BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
private String[][] commands = {{"newpassword", "listpasswords"},
{" - Saves the password you type", " - Shows a list of saved passwords."}};
public static void main(String[] args) throws IOException {
Main m = new Main();
while (true) {
System.out.println("Please type 'commands' to view a list of available commands, " +
"\nor just type in a command.");
m.getInput(m.input.readLine());
}
}
public void getInput(String cmd) throws IOException {
String password = input.readLine();
if (cmd.equals("commands")) {
for (int i = 0; i < commands.length; i++)
System.out.println("Current commands: " + commands[0][i] + commands[1][i]);
}
if (cmd.equals("newpassword")) {
writeToFile(password);
System.out.println("You typed" + password);
}
}
public void writeToFile(String toWrite) throws IOException {
FileWriter fstream = new FileWriter("password/file.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(toWrite);
out.close();
System.out.println("Wrote " + toWrite +" to file.");
}
}