一、数据类型
Android下资源文件大致分为两种,res目录下和assets目录下
res目录下文件,系统会在R.java里自动生成资源id,可以通过R.id.xxx进行访问
assets目录下文件,系统不会映射到R.java里,我们需要通过AssetManager来访问
assets可以有目录结构
二、图片
AssetManager assetManager = getAssets();
InputStream inputStream = assetManager.open("my_love_idle.jpg");
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
三、文本
private void getAssetsTextFile() {
AssetManager assets = getAssets();
try {
InputStream inputStream = assets.open("hello.txt");
File file = new File(getCacheDir(), "hello.txt");
FileOutputStream fileOutputStream = new FileOutputStream(file);
int len = -1;
byte[] buff = new byte[1024];
while ((len = inputStream.read(buff)) != -1) {
fileOutputStream.