简体   繁体   中英

Getting last modified date of a file not the last created date in Java

I had copied a file to my android device. When i check it's last modified date with file.lastModified() it returns the date the file was created which is just now. I want the original date when the file was last modified and not copied. I can see this date in windows explorer with the tag Date modified .The file.lastModified() matches with the Date created Tag of the file. If i could get the last Modified Date i can update the file with another file from server after it has been updated by just checking the date. But with created date it is not possible.

I got Creation date of a document using apache tika in java

Here is my java code to get creation date of document :

public class tikaExample {

    public static void main(String[] args) throws SAXException, TikaException {
        InputStream is = null;

        try {
            is = new BufferedInputStream(new FileInputStream(new File("/home/rahul/Downloads/darknet5.doc")));

            Parser parser = new AutoDetectParser();
            BodyContentHandler handler = new BodyContentHandler();

            Metadata metadata = new Metadata();

            parser.parse(is, handler, metadata, new ParseContext());
            System.out.println("creation date "+metadata.get(Metadata.CREATION_DATE));
            System.out.println("last modify date "+metadata.get(Metadata.LAST_MODIFIED));           
        } catch (IOException e) {
            e.printStackTrace();
        }

and output of this code is :

 creation date 2002-10-16T05:45:00Z
 last modify date 2013-07-01T05:12:00Z

that is creation date and time of file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM