public class Solution {
public static void main(String[] args) {
}
public static class PersonScannerAdapter implements PersonScanner {
private Scanner fileScanner;
public PersonScannerAdapter(Scanner fileScanner){
this.fileScanner=fileScanner;
}
@Override
public Person read() throws IOException, ParseException {
//Иванов Иван Иванович 31 12 1950
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("file.txt")));
String s1 = br.readLine();
br.close();
String[] s = s1.split(" ",4);
SimpleDateFormat format = new SimpleDateFormat("dd MM yyyy", Locale.ENGLISH);
Date d = format.parse(s[3]);
return new Person(s[1], s[2], s[0], d );
}
@Override
public void close() throws IOException {
fileScanner.close();
}
}
}package com.javarush.task.task19.task1904;
import java.util.Date;
public class Person {
private String firstName;
private String middleName;
private String lastName;
private Date birthDate;
public Person(String firstName, String middleName, String lastName, Date birthDate) {
this.firstName = firstName;
this.middleName = middleName;
this.lastName = lastName;
this.birthDate = birthDate;
}
@Override
public String toString() {
return String.format("%s %s %s %s", lastName, firstName, middleName, birthDate.toString());
}
}