Android import java.nio.file.Files; cannot be resolved

android, java, java-7

Solution

Android does not offer all classes that "conventional java" has to offer. `Files` is one of the classes, that Android doesn't offer.

You can have a look at the classes available in Android here: http://developer.android.com/reference/classes.html

So unfortunately you have to use other functions / classes to implement the same functionality.

PS: The class is shown in your screenshot because you browse the classes of java installed on your PC, not those that are be available on the Android phone / tablet.

Update

The `Files`/`FileSystem` classes have become available starting with API version 26.

Problem

I am trying out the new Gmail API and the samples use the classes in the java.nio.file package, e.i. `Files` and `FileSystems`. These classes was introduced in Java jdk 1.7 for the record, and since I am running jdk 1.7.0_65 in my Android app I have no idea why Android Studio cannot find these classes. The imports are: ``` import java.nio.file.FileSystems; import java.nio.file.Files; ``` My build.gradle file of course tells the system to use v. 1.7 like this ``` android { compileSdkVersion 19 buildToolsVersion '20' ... compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } } ``` I am pointing to the right directory of the jdk: The jdk is listed in the External Libraries section: And if I browse through the Java files I can even find java.nio.file.Files and .FileSystems: Now, what the **** is going on!? From my understanding I am doing everything right here, any suggestions?

Original source