问题
I'm using Android Studio 2.3.1 and jdk 1.8 for this project.
I import a project and it's using 'java.nio.file.Files' and 'java.nio.file.Paths'.
Package "java.nio.file" does not exist in Java 8.
Also Android Studio does not allow to select 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
回答1:
Good news: java.nio.* in now part of Android O!
More information here https://developer.android.com/reference/java/nio/package-summary.html
回答2:
Android does not offer all classes that "conventional Java" has to offer. Files are 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.
I found this library that claims to be
NNIO: A Java NIO.2 Substitute Library
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.
Edit: As Android O Developer Preview java.nio.file is supported. https://developer.android.com/reference/java/nio/file/package-summary.html
来源:https://stackoverflow.com/questions/43706789/alternative-to-java-nio-file