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

ε祈祈猫儿з 提交于 2020-01-15 11:31:46

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/18094492/getting-last-modified-date-of-a-file-not-the-last-created-date-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!