Getting last file access time using BasicFileAttri

2019-09-06 19:28发布

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条回答
Rolldiameter
2楼-- · 2019-09-06 19:46

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.

查看更多
登录 后发表回答