Trying to get a file path to a public folder on an

2019-09-18 12:23发布

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 enter image description here.

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);
        }
    }

2条回答
霸刀☆藐视天下
2楼-- · 2019-09-18 12:52

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-09-18 12:52

You may need to escape the spaces in your string

File fileOfEpubs = new File("/data/data/Folder\ of\ to\ get\ items\ from/");
查看更多
登录 后发表回答