获取文件的上次修改日期,而不是Java中的上次创建日期 [英] Getting last modified date of a file not the last created date in Java

查看:97
本文介绍了获取文件的上次修改日期,而不是Java中的上次创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将文件复制到我的android设备.当我使用file.lastModified()检查它的最后修改日期时,它返回文件的创建日期,即现在.我想要文件的最后修改日期而不是复制的原始日期.我可以在Windows资源管理器中看到此日期,其标记为Date Modify..file.lastModified()与该文件的创建日期标记匹配.如果我可以获取最后的修改日期,则可以通过仅检查日期来更新服务器上的另一个文件.但是使用创建的日期是不可能的.

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.

推荐答案

我在Java中使用 apache tika 获得了文档的创建日期

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

这是我的 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();
        }

此代码的

输出是:

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

即文件的创建日期和时间.

that is creation date and time of file.

这篇关于获取文件的上次修改日期,而不是Java中的上次创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆