AssetManager用于获取assets下的资源。

1、getassets()得到AssetManager 
2、AssetManager.close() 关闭AssetManager 
3、Resources和Assets 中的文件只可以读取而不能进行写的操作。 
4、AssetManager类常用方法:

返回指定路径下的所有文件及目录名:
final String[] list(String path)
使用 ACCESS_STREAMING模式打开assets下的指定文件:
final InputStream open(String fileName)
使用显示的访问模式打开assets下的指定文件:
final InputStream open(String fileName, int accessMode)

访问assets下的资源:

1、访问assets下的网页:

//实例化WebView对象
webview = new WebView(this);
//加载需网页
webview.loadUrl("file:///android_asset/index.html");
setContentView(webview);

注意:文件名字不能带有空格和其他非法字符,只能英文字母大小、数字、下划线。

2、访问图片和文本文件

 AssetManager asset=getAssets();
InputStream in=null;
try {
in=asset.open("images/logo.gif");
Bitmap bitmap=BitmapFactory.decodeStream(in);
imageview1.setImageBitmap(bitmap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} try {
in=asset.open("test/test.txt"); ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer=new byte[1024];
int byteCount=0;
while((byteCount=in.read(buffer))!=-1){
outSteam.write(buffer,0,byteCount);
}
byte[] buffer1=outSteam.toByteArray();
String str=new String(buffer1);
Log.i("Test", str); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

3、获取assets的文件及目录名:

// path为文件夹路径
String fileNames[] =context.getAssets().list(path);

AssetManager的更多相关文章

  1. Android ndk下用AssetManager读取assets的资源

    转自:http://www.cppblog.com/johndragon/archive/2012/12/28/196754.html 在使用 cocos2dx 在 Android 上进行游戏开发时, ...

  2. AssetManager asset的使用

    Android 系统为每个新设计的程序提供了/assets目录,这个目录保存的文件可以打包在程序里./res 和/assets的不同点是,android不为/assets下的文件生成ID.如果使用/a ...

  3. 简单改造 starling 中的 AssetManager 让其更适合 批次加载纹理

    API文档参考:http://doc.starling-framework.org/core/starling/utils/AssetManager.html 项目想以不改动starling的情况下对 ...

  4. AssetManager中的路径参数不能包含"assets/"

    String path = “music/bg.mp3”: //正确的参数 //String path = “assets/music/bg.mp3”: //错误的参数 //String path = ...

  5. AssetManager asset使用

    Android 该系统提供了一个程序为每个新的设计/assets文件夹.保存该文件在此文件夹可以在一个程序被打包./res 和/assets所不同的是,android不/assets下生成的文件ID. ...

  6. libgdx学习记录16——资源加载器AssetManager

    AssetManager用于对游戏中的资源进行加载.当游戏中资源(图片.背景音乐等)较大时,加载时会需要较长时间,可能会阻塞渲染线程,使用AssetManager可以解决此类问题. 主要优点: 1. ...

  7. assets raw 资源 AssetManager

    assets raw 目录简介 assets核心特性:不会被编译成二进制,支持子目录(可以分类,这是相对raw目录最大的好处),通过文件名访问,调用getAssets通过AssetManager访问 ...

  8. NDK,在JNI层使用AssetManager读取文件

    NDK,二进制文件数据读取,在JNI层,通过AAssetManager读取asset内部的资源: 需要头文件的支持 #include <android/asset_manager_jni.h&g ...

  9. Android之AssetManager使用

    1. 获取AssetManager AssetManager assetManager = context.getAssets(); 2. 列出assets文件夹下全部文件 String[] file ...

随机推荐

  1. LINUX文件内容处理及文本编辑器vim

    Linux基本操作命令 echo命令 echo命令: 把echo后面的内容显示到屏幕. -n 显示内容的时候不显示每行结尾的回车 echo 内容 >> 文件名 表示把内容加到一个文件的末尾 ...

  2. Redis、Memcache、MongoDb的优缺点

    Redis.Memcache.MongoDb的优缺点 Redis优点 支持多种数据结构,如 string(字符串). list(双向链表).dict(hash表).set(集合).zset(排序set ...

  3. C C++ 数字后面加 LL是什么意思

    long long类型,在赋初值的时候,如果大于2的31次方-1,那么后面需要加上LL

  4. Codeforces Round #428 (Div. 2) D. Winter is here 容斥

    D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at th ...

  5. vivox23幻彩版手机怎么设置双击息屏

    除了使用电源键来实现快速息屏方式外,我们还能通过双击屏幕的手势来息屏,下面小编就教大家vivox23幻彩版设置双击息屏的方法教程. vivox23幻彩版怎么设置双击息屏 第一步:打开vivox23幻彩 ...

  6. Vue(五)模板

    模板 1. 简介 Vue.js使用基于HTML的模板语法,可以将DOM绑定到Vue实例中的数据 模板就是{{}},用来进行数据绑定,显示在页面中 也称为Mustache语法 2. 数据绑定的方式 a. ...

  7. JAVA自学笔记15

    JAVA自学笔记15 @例题1:共有5个学生,请把五个学生的信息存储到数组中,并遍历数组,并获取每个学生的信息 Students[] students=new Student[5]; Student ...

  8. C#设置WebBrowser IE浏览器版本

    通过修改注册表的值,来指定winform程序打开的webBrowser的IE版本 1>方法一,通过程序修改注册表的值 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

  9. [asp.net core]The requested page cannot be accessed because the related configuration data for the page is invalid.

    bug HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the rela ...

  10. GoogLeNet 解读

    GoogLeNet系列解读 2016年02月25日 15:56:29 shuzfan 阅读数:75639更多 个人分类: 深度学习基础    版权声明:本文为博主原创文章,转载请注明出处 https: ...