问题
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