Android: path of assets folder for File()?

こ雲淡風輕ζ 提交于 2019-12-21 09:34:45

问题


I have some files in the assets folder of my project, and I want to list them, so I put this in my code:

File dir = new File("com.packagename/assets/fonts");
File[] fileList = dir.listFiles();

Which path should I put to make it work? I want it so users could install new fonts (I don`t know how to do this yet) so I need to list all the fonts in the folder, including post-installed fonts. If there is any other solutions, please share.


回答1:


Assets and resources are accessible using file:///android_asset and file:///android_res.

But in this case you will want to do something like this :

Resources res = getResources()
AssetManager am = res.getAssets();
String fileList[] = am.list(dirFrom);

if (fileList != null) {   
   for ( int i = 0;i<fileList.length;i++) {
        Log.d("",fileList[i]); 
    }
}


来源:https://stackoverflow.com/questions/13372500/android-path-of-assets-folder-for-file

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