Getting last file access time using BasicFileAttributes in Java SDK 1.8

牧云@^-^@ 提交于 2019-12-25 05:15:19

问题


I have seen most of the previous questions here on Java 1.7 and getting the last file access time.

Here's also a good snippet on import library and how they get the last file access time: http://kodejava.org/how-do-i-get-file-basic-attributes/

I did this:

BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
FileTime time = attrs.lastAccessTime();

However, in my IntelliJ IDEA IDE it says, BasicFileAttributes could not be resolved.

So, I imported this:

import java.nio.file.attribute.BasicFileAttributes;

But apparently, file cannot be resolved. I am running Java SDK 1.8 and I am trying to use this in my Android project if that makes a difference.

Not sure why file is missing in the library.

What could I be doing wrong?


回答1:


Currently Android doesn't support all Java 7 features so forget about Java 8. I mentioned Java 7 because Files was introduced in Java 7. Some features like multi-catch are supported by Android(and starting with Kitkat try-with-resources ) but Files class is not. Note that Google doesn't use Oracle Java.



来源:https://stackoverflow.com/questions/25898256/getting-last-file-access-time-using-basicfileattributes-in-java-sdk-1-8

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