gpt4 book ai didi

android - Android 上的文件上次访问时间

转载 作者:太空宇宙 更新时间:2023-11-03 10:46:37 25 4
gpt4 key购买 nike

有没有办法在 Android 中获取文件的上次访问时间。我知道如何使用 java nio.file 包来做到这一点,但是,Android 对 java 7 的支持非常有限,不包括文件包。我对 lastModified 不感兴趣,只对 lastAccessed 感兴趣,因为我想删除最旧的读取​​文件。

最佳答案

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
StructStat stat = null;
try {
stat = Os.stat("/sdcard/Pictures/abc.jpg"); // File path here
} catch (ErrnoException e) {
e.printStackTrace();
}
long t2 = stat.st_atime *1000L;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(t2);

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh-MM-ss");
String formattedDate = formatter.format(calendar.getTime());}

虽然这仅适用于以上 Lollipop API。

另请注意,st_atime 以秒而非毫秒返回时间。

关于android - Android 上的文件上次访问时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22407071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com