Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get autogenerated folder path in java to parse files from a folder

Tags:

java

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?

like image 944
Bala K Avatar asked Dec 20 '25 14:12

Bala K


1 Answers

Try this. I think this works.

File f = new File("/data/test/files/" + thisYear+ "/" + thisMonth+ "/" +thisDay + "/refile.txt");
like image 195
TwilightTitus Avatar answered Dec 22 '25 03:12

TwilightTitus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!