Привет всем, в файле строка
Ivanov Ivan-Petr Ivanich 31 12 1987
проверял чему равно name и date:
31 12 1987
Ivanov Ivan-Petr Ivanich
Вывод такой. Так а что тогда не так?
package com.javarush.task.task19.task1921;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/*
Хуан Хуанович
*/
public class Solution {
public static final List<Person> PEOPLE = new ArrayList<Person>();
public static void main(String[] args) {
String name ="";
String date="";
int x = 0;
try {
BufferedReader reader = new BufferedReader(new FileReader(args[0]));
String str ;
while ((str=reader.readLine())!=null) {
String[] lines = str.split(" ");
for (String s : lines) {
try {
x = Integer.parseInt(s);
date += x + " ";
} catch (NumberFormatException e) {
name += s + " ";
}
}
name = name.substring(0, name.length() - 1);
date = date.substring(0, date.length() - 1);
SimpleDateFormat format = new SimpleDateFormat("d M yyyy");
Date dates = format.parse(date);
PEOPLE.add(new Person(name, dates));
}
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}