简体   繁体   English

java.nio.file的替代品

[英]Alternative to java.nio.file

I'm using Android Studio 2.3.1 and jdk 1.8 for this project. 我正在为这个项目使用Android Studio 2.3.1和jdk 1.8。

I import a project and it's using 'java.nio.file.Files' and 'java.nio.file.Paths'. 我导入一个项目,它使用'java.nio.file.Files'和'java.nio.file.Paths'。

Package "java.nio.file" does not exist in Java 8. Java 8中不存在包“java.nio.file”。

Also Android Studio does not allow to select jdk 1.7. Android Studio也不允许选择jdk 1.7。

What can i do with this code ? 我该怎么办这个代码?

public void toFile(final String path) throws IOException {
    Files.write(Paths.get(path), toBuffer());
}

and this code 和这段代码

public static Source fromFile(final String path) throws IOException {
    return fromBuffer(Files.readAllBytes(Paths.get(path)));
}

** (Cannot resolve Files and Paths) **(无法解析文件和路径)

Thanks 谢谢

Good news: java.nio.* in now part of Android O! 好消息:java.nio。*现在是Android O的一部分!

More information here https://developer.android.com/reference/java/nio/package-summary.html 更多信息请访问https://developer.android.com/reference/java/nio/package-summary.html

Android does not offer all classes that "conventional Java" has to offer. Android不提供“传统Java”必须提供的所有类。 Files are one of the classes, that Android doesn't offer. 文件是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. 所以,遗憾的是,您必须使用其他函数/类来实现相同的功能。

I found this library that claims to be 我发现这个图书馆声称是

NNIO: A Java NIO.2 Substitute Library NNIO:Java NIO.2替代库

but I think you should use instead guava to implement the same functionality, as it is used in many first-class apps and has a big community. 但我认为您应该使用guava来实现相同的功能,因为它在许多一流的应用程序中使用,并且拥有一个庞大的社区。

Edit: As Android O Developer Preview java.nio.file is supported. 编辑:支持Android O Developer Preview java.nio.file。 https://developer.android.com/reference/java/nio/file/package-summary.html https://developer.android.com/reference/java/nio/file/package-summary.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM