assets文件夹里面的文件都是保持原始的文件格式,需要用AssetManager以字节流的形式读取文件。
1. 先在Activity里面调用getAssets() 来获取AssetManager引用。
PS:在onCreate方法中使用getAssets时需要注意,要使用getBaseContext().getAssets() (因为在onCreate中 还没有创建好Activity 所以应该又构造函指定的上下文 详细见:http://blog.youkuaiyun.com/CodeNoodles/article/details/48811515)
2. 再用AssetManager的open(String fileName, int accessMode) 方法则指定读取的文件以及访问模式就能得到输入流InputStream。
4.调用AssetManager.close() 关闭AssetManager。
assets文件夹资源的访问
最新推荐文章于 2020-05-21 16:13:08 发布
本文介绍如何在Android应用中通过AssetManager读取assets文件夹内的文件。具体步骤包括:获取AssetManager实例、使用open方法读取文件并返回输入流以及关闭AssetManager。注意在特定情况下如何正确获取AssetManager实例。
797

被折叠的 条评论
为什么被折叠?



