0

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?

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
Kala J
  • 2,040
  • 4
  • 45
  • 85
  • Android has it's own libraries. It covers most of what the standard JDK has, but it's still missing parts from JDK 7 and everything from JDK 8. If you are using a really old ADK version, though, you won't even have access to anything from JDK 7. – Steffen Sep 17 '14 at 18:57
  • Hm even though, I download this JDK recently: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html and included it in my android project? – Kala J Sep 17 '14 at 18:59

1 Answers1

2

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.

sol4me
  • 15,233
  • 5
  • 34
  • 34
  • Is there something I can use in Android to get the time of last file access or if I sync with a device, is there a way to get last time sync with device? (last file access is a placeholder for the latter). – Kala J Sep 17 '14 at 19:30
  • You have File class in android that supports some time related functionality but if you want something more then write NDK wrapper – sol4me Sep 17 '14 at 19:46
  • What do you mean by write an NDK wrapper? – Kala J Sep 17 '14 at 20:19
  • I mean that under the hood we are using linux so you can use stat, http://man7.org/linux/man-pages/man2/stat.2.html – sol4me Sep 17 '14 at 20:27
  • What would be the simplest approach to using stat in android? – Kala J Sep 17 '14 at 20:52
  • AS i mentioned by writing NdkWrapper around stat(), you can read some info regarding NdkWrapper here https://software.intel.com/en-us/android/articles/ndk-android-application-porting-methodologies – sol4me Sep 17 '14 at 21:30
  • Seems unnecessarily complex but thanks for your help! I appreciate it :D – Kala J Sep 17 '14 at 21:46
  • Things would be much smoother if there would be no Google vs Oracle issue – sol4me Sep 17 '14 at 21:48