Alternative to java.nio.file

I am using Android Studio 2.3.1 and jdk 1.8 for this project.

I am importing a project and using 'java.nio.file.Files' and 'java.nio.file.Paths'.

The "java.nio.file" package does not exist in Java 8.

Also Android Studio doesn't let you 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)));
}

      

** (Unable to resolve files and paths)

thank

+3


source to share


2 answers


Android does not offer all the classes that "regular Java" has to offer. Files are one of the classes that Android doesn't offer.

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

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

I found this library which claims to be



NNIO: Java NIO replacement library.2

but i think you should use guava instead to implement the same functionality as many first class applications has a large community.

Edit: java.nio.file is supported as Android Ovi preview. https://developer.android.com/reference/java/nio/file/package-summary.html

+1


source


Good news: java.nio. * Currently part of Android O!



More info here https://developer.android.com/reference/java/nio/package-summary.html

+1


source







All Articles