I want to add text file data to an ArrayList. This is my text file
60000115 2016-10-26-05:57:47
60000104 2016-10-26-05:58:27
60000082 2016-10-26-05:58:38
60000074 2016-10-26-06:01:04
I am split data using space. So there are bassically two part. Id and Date. I created a bean class called Employee with two String called user_id and mDate. employeArrayList is the ArrayList that i created using Employee class. Problem is I cannot add values to the Arraylist. Only the last row data is inserting to the ArrayList. For ex :- 60000074 2016-10-26-06:01:04 . Four rows of 60000074 2016-10-26-06:01:04 .
This is my code.
for (File f : files) {
FileInputStream fis;
try {
fis = new FileInputStream(f);
BufferedReader in = new BufferedReader(new InputStreamReader(fis));
String aLine;
while ((aLine = in.readLine()) != null) {
String[] tokens = aLine.split(" ");
emp.setUser_id(tokens[0]);
emp.setmDate(tokens[1]);
employeArrayList.add(emp);
out.write(aLine);
out.newLine();
}
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}