I have a text file of ID numbers and dates in this format:
ID Date
1 14/03/2011
2 06/03/2013
3 25/02/2013
4 28/01/2013
5 13/07/2011
6 13/03/2011
7 01/10/2012
8 09/10/2012
I need to read this txt file and store each date in a dictionary like a hashmap or something in the format. Also, it would be preferable if the dates are in the DATE
data type and not String.
I tried to do it myself but I am a beginner in JAVA and I couldn't get it done.
Thanks in advance for any help
This is what I've tried till now. I haven't used a dictionary, I tried to put the dates in an ArrayList and for some reason, it reads only every alternate line from the file so half the dates are missing.
static Date[] list = new Date[59400];
public static void main(String[] args) {
try {
File file = new File("dates.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String readLine = "";
int i =0;
while ((readLine = bufferedReader.readLine()) != null) {
String s = bufferedReader.readLine();
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(s);
System.out.println(s+","+i);
i++;
}
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}