Home > front end >  An elegant way to extract 'Date' attribute from a File
An elegant way to extract 'Date' attribute from a File

Time:07-14

So I have multiple files (on Windows 10 operating system and NTFS file system) with 'Date' attributes as here

'Date' attributes are available in Windows File Explorer in the 'Details' view after enabling them.

I'm looking for the easiest way to extract this attribute in Java (or Scala). I've read about solutions that can extract modification/creation time but neither of them mentioned a 'Date' attribute alone.

CodePudding user response:

So apparently this 'Date' attribute has the same value as 'Last Saved Date' which is attribute specific to Microsoft Office or only (?) Excel files... The method to extract this data from a file in Scala (if you use org.apache.poi.hssf library) can look something like this

def getLastSaveDateTime(file: File): Date = {
  val fileInputStream = new FileInputStream(file)
  try {
    val workbook = new HSSFWorkbook(fileInputStream)
    workbook.getSummaryInformation.getLastSaveDateTime
  } finally fileInputStream.close()
}
  • Related