Tell me how in Android Studio through IO to open a file from anywhere in the file system?

From my experience in Java programming, I know that on a PC, in any OS, you can simply specify the path when creating a FileReader object, and everything will work fine. In Android, this does not work for me, FileNotFound is constantly being thrown away.

enter image description here

    1 answer 1

    Open the file from anywhere in the file system without root-rights will not work.

    The Android application has access to two main file storages:

    • Internal Storage is the area of ​​memory that is allocated for each application;
    • External Storage is some kind of external storage (for example, a memory card).

    As I understand it, you are interested in the second type. You can access the root directory of external storage using the getExternalStorageDirectory() method, which returns a File object. Get the path to the root repository as follows:

     String path = getExternalStorageDirectory().getAbsolutePath(); 

    And then you can start from this path.

    • I understand that I will receive the directory that I specified when creating the File object? - Nick
    • 3
      @ Nick, no. You do not create an object of the File class, it is returned to you by the getExternalStorageDirectory() method. In general, this is a fairly voluminous topic with a lot of pitfalls, you can read more about working with files in the official documentation . - post_zeew
    • Thank you very much. - Nick