私はあなたが言うことができると確信していますが、私はjavaに新しいです。 とにかく私は人がファイルに他の名前と情報があるときにtxtファイルから検索するために名前をタイプした後に次の3行を読み込もうとしています。情報は、名字、姓、ID番号、年数を尋ねた別のプログラムからtxtファイルに入れられ、別々の行に印刷されました。これは私がこれまで持っていたものです。.txtファイルから名前を読み取った後、次の3行を印刷するにはどうすればよいですか?
System.out.println("Please enter first name of employee.");
String employeeName = keyboard.nextLine();
// Check to see if the name is in the file
// And for some reason if the name is in it, it says that it's not
if(fileName.contains(employeeName))
{
System.out.println("Sorry, that employee is not in the file.");
}
else
{
// Read the last name.
String lastName = inputFile.nextLine();
System.out.println(lastName);
// Read the employee number
String employeeID = inputFile.nextLine();
System.out.println(employeeID);
// Read the years of experience
String years = inputFile.nextLine();
System.out.println(years);
}
'for'のようなループを使うこともできます。 – Akbari
'keyboard'の読み込みから' inputFile'の読み込みに切り替えたようです。 –
私はforループの使い方を考えようとしていましたが、どのように考えるべきか分からなかった。 – Ryfool