apk安装以后放在/data/app/**.apk,以apk形式存在,asset/res和apk在一起,并不会解压到/data/data/YourApp目录下去,所以你无法直接获取到assets的绝对路径,因为他根本没有;
所以我们只能通过文件读写的方式,写到缓存文件里面去,通过获取缓存文件路径 来读取,见如下代码 ,byte的size根据自己文件大小来确认,可自己调整。
public String getAssetsCacheFile(Context context,String fileName)   {
        File cacheFile = new File(context.getCacheDir(), fileName);
        try {
            InputStream inputStream = context.getAssets().open(fileName);
            try {
                FileOutputStream outputStream = new FileOutputStream(cacheFile);
                try {
                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = inputStream.read(buf)) > 0) {
                        outputStream.write(buf, 0, len);
                    }
                } finally {
                    outputStream.close();
                }
            } finally {
                inputStream.close();
            }
        } catch (IOException e) {
           e.printStackTrace();
        }
        return cacheFile.getAbsolutePath();
    }


GitHub 加速计划 / ass / assets
30
1
下载
Ultralytics assets
最近提交(Master分支:4 个月前 )
9306bfc9 2 天前
f3ad6b8c 2 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐