安卓:资产文件夹中的文件路径()? [英] Android: path of assets folder for File()?

查看:183
本文介绍了安卓:资产文件夹中的文件路径()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目的资产文件夹中的一些文件,我想一一列举,所以我在code把这样的:

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.

推荐答案

资产和资源的访问使用file:/// android_asset和文件:/// android_res

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

这篇关于安卓:资产文件夹中的文件路径()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆