Trying to get a file path to a public folder on android device and get its content

二次信任 提交于 2019-12-12 05:17:26

问题


I am looking to get the file path of a folder and then get its content. The folders are a public folder that you can access by just connecting the device into the computer. How do I go about getting a the file path to get access to these public folders and then get all its content?

So once I connect my computer to the device these are the folders I see and there is one that says "Folder to get items from" and I can't seem to figure what the file path is in order to get access to its content .

This is how I'm trying to get its content and Log them

    File fileOfEpubs = new File("/data/data/Folder of to get items from/");


    File[] dirEpub = fileOfEpubs.listFiles();

    if (dirEpub.length != 0){
        for (int i = 0; i < dirEpub.length; i++){
            String fileName = dirEpub[i].toString();
            Log.i("File", "File name = " + fileName);
        }
    }

回答1:


You appear to be looking at the root of external storage. Programmatically, you access that via Environment.getExternalStorageDirectory(). That requires either the READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE permission.




回答2:


You may need to escape the spaces in your string

File fileOfEpubs = new File("/data/data/Folder\ of\ to\ get\ items\ from/");


来源:https://stackoverflow.com/questions/34658494/trying-to-get-a-file-path-to-a-public-folder-on-android-device-and-get-its-conte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!