安卓导入java.nio.file.Files;无法解决
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24869323/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android import java.nio.file.Files; cannot be resolved
提问by Jakob
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
.
我正在试用新的 Gmail API,示例使用 java.nio.file 包中的类 eiFiles
和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.
这些类是在 Java jdk 1.7 中引入的,因为我在我的 Android 应用程序中运行 jdk 1.7.0_65,我不知道为什么 Android Studio 找不到这些类。
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
我的 build.gradle 文件当然告诉系统像这样使用 v. 1.7
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:
我指向 jdk 的正确目录:
The jdk is listed in the External Libraries section:
jdk 列在外部库部分:
And if I browse through the Java files I can even find java.nio.file.Files and .FileSystems:
如果我浏览 Java 文件,我什至可以找到 java.nio.file.Files 和 .FileSystems:
Now, what the **** is going on!? From my understanding I am doing everything right here, any suggestions?
现在,该死的到底是怎么回事!?根据我的理解,我在这里做所有事情,有什么建议吗?
采纳答案by fabian
Android does not offer all classes that "conventional java" has to offer. Files
is one of the classes, that Android doesn't offer.
Android 并未提供“传统 Java”必须提供的所有类。Files
是 Android 不提供的类之一。
You can have a look at the classes available in Android here: http://developer.android.com/reference/classes.html
您可以在此处查看 Android 中可用的类: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.
PS:该类显示在您的屏幕截图中是因为您浏览的是PC上安装的java类,而不是Android手机/平板电脑上可用的类。
Update
更新
The Files
/FileSystem
classes have become available starting with API version 26.
该Files
/FileSystem
班已成为开始可用API版本26。
回答by Simmant
回答by stone
Apparently java.nio.file
is coming with Android O.
https://developer.android.com/reference/java/nio/file/package-summary.html
显然java.nio.file
是 Android O.
https://developer.android.com/reference/java/nio/file/package-summary.html