Get File Creation Time

北城以北 提交于 2019-12-24 02:02:33

问题


I want to get a time of all files that are in this folder ("/sdcard/Files/"). And then I want to delete all the files that have more than one hour.

Is there any method to do it?


回答1:


    File dir = new File("/sdcard/Files/");
    File[] files = dir.listFiles();
    for (int i = 0; i < files.length; ++i){
        long lastTime = files[i].lastModified();
        Date nowDate = new Date();
        long nowTime = nowDate.getTime();
        if (nowTime - lastTime > 60*60*1000){
            files[i].delete();
        }
     }

I hope it can help you.



来源:https://stackoverflow.com/questions/9168822/get-file-creation-time

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