In Unix created a folder path like /data/test/files/2015/05/19. From year, folder is autogenerated /data/test/files/$(date +%Y)/$(date +%m)/$(date +%d)
So .txt file inside the above folder location should be parsed through Java code and moved to DB.
I tried to parse that location as 2015/05/19 will change in future, so tried to append current year/month/day in Java and then parse that particular file.
//To get current year
String thisYear = new SimpleDateFormat("yyyy").format(new Date());
System.out.println("thisYear :"+thisYear);
//To get current month
String thisMonth = new SimpleDateFormat("MM").format(new Date());
System.out.println("thisMonth : "+thisMonth);
//To get current date
String thisDay = new SimpleDateFormat("dd").format(new Date());
System.out.println("thisDay : "+thisDay);
File f = new File("\\data\\test\\files\\+"thisYear"+\\+"thisMonth"+\\+"thisDay"+ \\refile.txt");
The above didn't work so how can I use thisYear,thisMonth,thisDay in path?
Try this. I think this works.
File f = new File("/data/test/files/" + thisYear+ "/" + thisMonth+ "/" +thisDay + "/refile.txt");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With