简体   繁体   English

Android:File()的资产文件夹路径?

[英]Android: path of assets folder for File()?

I have some files in the assets folder of my project, and I want to list them, so I put this in my code: 我的项目的Assets文件夹中有一些文件,我想列出它们,因此将其放在代码中:

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. 如果还有其他解决方案,请分享。

Assets and resources are accessible using file:///android_asset and file:///android_res. 使用file:/// android_asset和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]); 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM