次のテキストファイルがあります。
First Name : Javier Last Name : Smith E-mail : smith@.com Password: jsmith Date of Birth: Jan 1, 1987
First Name : Jade Last Name : Tux E-mail : nicholson@.com Password: jade123 Date of Birth: Jan 1, 1954
First Name : Bruce Last Name : Porto E-mail : bruce_porto@.com Password: br11 Date of Birth: Feb 25, 1946
最初の行で文字列 Javier、Smith、smith@.com、jsmith などを取得し、これらの文字列を person 型 (文字列、文字列、文字列、文字列) の配列リストに格納し、各行で同じことを行います。
これまでの私のコードは次のとおりです。
try
{
searchUser = new Scanner(new FileInputStream("src/users.txt")).useDelimiter(":");
String storeFirst = "", storeLast = "", storeEmail = "", storePassword = "";
usersArray = new ArrayList<Person>();
String line = null;
while(searchUser.hasNextLine())
{
line = searchUser.nextLine();
storeFirst = searchUser.next();
storeLast = searchUser.next();
storeEmail = searchUser.next();
storePassword = searchUser.next();
line = searchUser.nextLine();
usersArray.add(new Person(storeFirst, storeLast, storeEmail, storePassword));
for(Person ae : usersArray)
{
System.out.println(ae.toString());
}
System.out.println(storeFirst);
System.out.println(storeLast);
System.out.println(storeEmail);
System.out.println(storePassword);
}
searchUser.close();
}