简体   繁体   English

获取文件的上次修改日期,而不是Java中的上次创建日期

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

I had copied a file to my android device. 我已将文件复制到我的android设备。 When i check it's last modified date with file.lastModified() it returns the date the file was created which is just now. 当我使用file.lastModified()检查它的最后修改日期时,它返回文件的创建日期,即现在。 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. 我可以在Windows资源管理器中看到此日期,其标记为Date Modify.。file.lastModified()与该文件的创建日期标记匹配。 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 我在Java中使用apache tika获得了文档的创建日期

Here is my java code to get creation date of document : 这是我的Java代码,用于获取文档的创建日期

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. 即文件的创建日期和时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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