android - 获取文件的最后修改日期

标签 android

我正在使用它来查看文件是否已经存在并获取其时间戳:

File file = new File(getResources().getString(R.string.file_name));

if (file.exists()) {
  Date lastModified = new Date(file.lastModified());
}

虽然我可以使用 Context.fileList() 方法看到这个文件确实存在,但上面的代码总是说它不存在。

如何获取文件的最后修改日期?

最佳答案

我认为你的问题是 file.exists() 失败,修改日期的问题与它无关。

我敢说您使用的路径是您的应用程序的本地路径?使用 File 时需要使用绝对路径。

关于android - 获取文件的最后修改日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4102193/

相关文章:

android - Actionbar setTitle() 在 OnPageChangeListener() 中只工作一次

java - 如何通过用户输入从sqlite检索数据

Android 工具栏溢出菜单 View ID

java - 无法写入内部存储

android - 发布多个具有不同 Android 版本的 APK

android - 在 android ListView 中滚动如何工作?

android - 在 CoordinatorLayout 中使用带有 AppBarLayout anchor 的 Button 而不是 FloatingActionButton

android - 使用 surfaceView 捕捉视频

android - 处理异步任务返回的数据 (Firebase)

android - 线程中的 Kotlin runnable 使用的值与传递的值不同