簡體   English   中英

Android:File()的資產文件夾路徑?

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

我的項目的Assets文件夾中有一些文件,我想列出它們,因此將其放在代碼中:

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

我應該采用哪種方法使其起作用? 我想要它,以便用戶可以安裝新字體(我還不知道該怎么做),所以我需要列出文件夾中的所有字體,包括后安裝的字體。 如果還有其他解決方案,請分享。

使用file:/// android_asset和file:/// android_res可以訪問資產和資源。

但是在這種情況下,您將需要執行以下操作:

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