私は、パスワードを含むキーファイルの入力を求めるプロンプトを出す方法を教えてください。私は数日間この作業に取り組んできました。それは私の大学ファイナルプロジェクトのためのものです。私はこの1つのプログラムを構築し続けると、一連のキーを作成することができたので、 1つのメインファイルに到達する。アイデアは高く評価されました。ユーザーがある時点でログインしたいと思っているかどうかを尋ねる、ログインに成功する前にプロンプトを追加します。鍵照合システムのファイルアップロードのプロンプトを追加するにはどうすればよいですか?
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner; // Needed for the Scanner class
public class TxtKeyVerifier {
public static void main(String[] args) throws FileNotFoundException {
File keyfile = new File("key2.txt");
Scanner sc = new Scanner(keyfile);
Scanner keyboard = new Scanner(System.in); //<<<---
String input;
System.out.print("Please enter your password: "); //<<---
input = sc.nextLine();
if (authenticate1(input)) {
System.out.println("This program is working if this text is found within outputfile.txt.");
File outputfile = new File("outputfile.txt");
FileOutputStream fos = new FileOutputStream(outputfile);
PrintStream ps = new PrintStream(fos);
System.setOut(ps);
System.out.println("This program is working if this text is found within outputfile.txt.");
}else if (authenticate2(input)) {
System.out.println("It works.");
}else{
System.out.println("Error: Wrong password.");
}
}
private static boolean authenticate1(String password1) {
return ((password1.length() == 6)
&& (password1.matches("beep11"))
&& (password1.matches("beep11"))
&& (password1.matches("beep11")));
}
private static boolean authenticate2(String password2) {
return ((password2.length() == 6)
&& (password2.matches("beep22"))
&& (password2.matches("beep22"))
&& (password2.matches("beep22")));
}
}
あなたは何を求めているのですか?ユーザーはファイルパスを入力する必要がありますか? –
はい、ユーザー入力はパスワードが入った.txtファイルにします。 – NumaNuma
このようなものhttp://stackoverflow.com/questions/3309899/how-to-pass-a-text-file-as-a-argumentまたはhttp://stackoverflow.com/questions/13185727/reading-a- txtファイルを使用するスキャナクラスのJava –