I would like to list files contained into assets subdirectory called “subDir” and am using following code. However, if I set dirFrom = “” (empty), lists all folders in assets properly. However, for dirFrom = “/subDir/”, doesn’t work. I already tried “subDir/” and same result. Is necessary to declare permissions in manifest? Thank you.
private void copyFiles(String dirFrom, String dirTo) throws IOException {
AssetManager am = getAssets();
String fileList[] = am.list(dirFrom);
if (fileList != null)
{
for ( int i = 0;i<fileList.length;i++)
{
Log.d("",fileList[i]);
}
}
}
AssetManager.list(String) takes a “relative path within the assets”.
Android / Java usually expects paths to have no
'/'in the end.Also “relative” means that there should be no
'/'at the start – it could otherwise be a path in the root of your filesystem.Using just
"subDir"or"subDir/subsubDir"will work.