I am uploading a file using Spring MultipartFile. I need to store the uploaded file attributes like creation date and modified date. Currently I am using following approach:
File dest = new File(uploadfile.getOriginalFilename());
dest.createNewFile();
FileOutputStream fos = new FileOutputStream(dest);
fos.write(uploadfile.getBytes());
fos.close();
Path filee = dest.toPath();
BasicFileAttributes attr = Files.readAttributes(filee, BasicFileAttributes.class);
System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());
where uploadfile is the object of spring boot MultipartFile.
Referred links :
How to convert a multipart file to File?
Get java.nio.file.Path object from java.io.File
Determine file creation date in Java
The issue is that I am getting creation date and modified date as the current date only and probably the reason is that the new file object is resetting these values. How can I get the attributes of the original uploaded file?