为什么不setLastModified(时间)这个文件的工作? [英] Why doesn't setLastModified(time) work for this File?

查看:144
本文介绍了为什么不setLastModified(时间)这个文件的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在下面的代码中文件的日期没有改变?

fLocal.location =现有的文件在C:\



fLocal.date =要设定的日期长

  boolean x = new File(fLocal.location).setLastModified(Long.parseLong(fLocal.date)); 
System.out.println(Changed:+ x);
System.out.println(new Date(new File(fLocal.location).lastModified()));
System.out.println(new Date(Long.parseLong(fLocal.date)));

输出:

 更改:false 
Fri Feb 15 23:02:51 CET 2013
Fri Feb 15 22:49:34 CET 2013

$ b $ div class =h2_lin>解决方案


  • 您的代码是否具有对文件的写入权限?

  • 文件是否处于打开状态?

  • 您目前正在阅读(或书写)这个?

  • 这些都是可能阻止您更改文件时间的项目。

    用一行文本创建一个简单的纯文本文件,保存并关闭编辑器。然后尝试在您的应用程序中使用该文件。确保在 File Object 上调用 exists()在尝试更改它的时间以确保您实际上拥有有效的文件之前。


    Why is the date of the file in the following code not changed?

    fLocal.location = Existing file in C:\

    fLocal.date = Date to set in Long

    boolean x = new File(fLocal.location).setLastModified(Long.parseLong(fLocal.date));
    System.out.println("Changed: " + x);
    System.out.println(new Date(new File(fLocal.location).lastModified()));
    System.out.println(new Date(Long.parseLong(fLocal.date)));
    

    Output:

    Changed: false
    Fri Feb 15 23:02:51 CET 2013
    Fri Feb 15 22:49:34 CET 2013
    

    解决方案

    From my comments from earlier, follow these checks:

    1. Does your code have write access to the file?
    2. Is the file in open status?
    3. Are you currently reading (or writing!) the file with any other application at the time you are doing this?

    These are all items that might prevent you from changing the time of the file.

    Create a simple plain text file with a single line of text, save it and close out of the editor. Then try using that file in your application. Make sure you call exists() on your File Object before you try to change the time of it to ensure you actually have a valid file.

    这篇关于为什么不setLastModified(时间)这个文件的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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