Since the details are not crystal clear I will use the following code. I assume you will use Linux
or Windows
OS
and got some files in a Directory
target as per maven
outputs stored.
You will need to get the files in the Directory to an Array
and iterate with the below code. This will get you the last modified date in each of the files iterated in LONG
and you will need SimpleDateFormat
to display in Date and Time.
// get the directory and iterate file one by one then the code:
File file = new File("\home\noname\xyz.txt"); // assume read file is xyz.txt
String fileName = file.getAbsoluteFile().getName();
long fileLastModifiedDate = file.lastModified();
// returns last modified date in long format
System.out.println(fileLastModifiedDate);
// e.g. 1644199079746
Date date = new Date(fileLastModifiedDate);
// create date object which accept long
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy hh:mm:ss");
// this is the format I assume, but can be changed as preferred : 12 December 2022, 11:59:22
String myDate = simpleDateFormat.format(date);
// accepts date and returns String value
System.out.println("Last Modified Date" + myDate);
// displays: 12 December 2022, 11:59:22
You may have a look below URL to come up with your own SimpleDateFormat if you do not prefer the one I used.
https://javadevtools.com/simpledateformat
Thanks.