获得文件的创建时间 [英] Get File Creation Time
本文介绍了获得文件的创建时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获得此文件夹(/ SD卡/文件/)中的所有文件的时间。然后我想删除所有有超过一小时的文件。
有没有什么方法呢?
解决方案
文件DIR =新的文件(/ SD卡/文件/);
文件[] =文件dir.listFiles();
的for(int i = 0; I< files.length ++我){
长lastTime =文件[I] .lastModified();
日期nowDate =新的日期();
长nowTime = nowDate.getTime();
如果(nowTime - lastTime→60 * 60 * 1000){
文件[I] .delete();
}
}
我希望它可以帮助你。
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?
解决方案
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.
这篇关于获得文件的创建时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文