How to use java.nio.file package in android?

10,052

Originally: the simple answer was that you can't do it. Android is Java 6 based, and (AFAIK) there is no backport of Java 7's java.nio.file classes to Android.

(That's not surprising. Porting java.nio.file would entail significant changes to the Davlik VM's native code libraries.)

Updated: according to the Android javadocs, support for the java.nio.file package was added to Android in API level 26. That corresponds to the Oreo release which came out in August 2017.


Can you tell me that what API should I use for my requirements. ( My requirement is File operation like : Cut|copy|delete on files and directories);

Prior to Android 26, I suggest you just use the java.io.File class for things like making directories, renaming files, and so on, and then implement the "higher level" operations such as copying files and directory trees using File.list() and FileInpuStream or FileOutputStream. You could possibly simplify some operations using classes such as the Apache commons DirectoryWalker FileUtils or Guava Files.

However, I'm not sure what you are trying to achieve here. There are already existing "file manager" apps for Android.

Share:
10,052
Paramananda
Author by

Paramananda

Updated on June 14, 2022

Comments

  • Paramananda
    Paramananda about 2 years

    I want to create a file manager application for Android using java.nio.file API which is the part of JDK7. I think this (java.noi.file)API contains easy solutions to design file manager application where JDK6(IO) and apache commons IO API does not have the same facility.

    Please give some solution, how I use the JDK7 (IO) in android application.

    Thanks!

  • machinezhou
    machinezhou over 8 years
    hi, I'm wondering that since I cannot import nio.files and other project like okio also cannot find this package in IDE, but how's okio works eventruelly?Really confused, can you tell me why and how can I do this like okio?'stackoverflow.com/questions/36184599/…'
  • Stephen C
    Stephen C over 7 years
    @machinezhou - Well, that seems to say that someone was trying to compile Okio in Android Studio and failed. Same as you. Obviously you can compile and run Okio on a real Java(tm) platform. That is what it is designed for!